Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
700d553b11 | ||
|
|
5339934d9d | ||
|
|
33fa7bcf37 | ||
|
|
cb7ed3ed68 | ||
|
|
7031544ce5 | ||
|
|
6f4b3e56d4 | ||
|
|
b438f52dec | ||
|
|
b10b495fa6 | ||
|
|
752ba245a9 | ||
|
|
3ad019f44b | ||
|
|
727b562e21 | ||
|
|
ce3fe12e45 | ||
|
|
f548329a4a |
No files matched your search
+2
-1
@@ -1,4 +1,5 @@
|
||||
.idea/
|
||||
build/
|
||||
*.iml
|
||||
.gradle
|
||||
.gradle
|
||||
/repos
|
||||
@@ -12,5 +12,6 @@ repositories {
|
||||
dependencies {
|
||||
compile 'org.tmatesoft.svnkit:svnkit:1.8.10'
|
||||
compile 'com.jgoodies:forms:1.2.1'
|
||||
compile 'com.jcraft:jsch:0.1.53'
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
package com.svn.utils.mirror;
|
||||
|
||||
import com.svn.utils.mirror.app.Mirror;
|
||||
import com.svn.utils.mirror.gui.main.MainWindow;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
|
||||
import java.io.IOException;
|
||||
import com.svn.utils.mirror.gui.main.ConnectOrCreateWindow;
|
||||
|
||||
/**
|
||||
* SvnMirror
|
||||
@@ -12,20 +8,6 @@ import java.io.IOException;
|
||||
*/
|
||||
public class SvnMirror {
|
||||
public static void main(String[] args) {
|
||||
|
||||
//new MainWindow("HelloWorldSwing");
|
||||
Mirror mirror = Mirror.getInstance();
|
||||
try {
|
||||
//mirror.createBaseRepo("base");
|
||||
//mirror.createMirrorRepo("mirror");
|
||||
mirror.loadBaseRepositoryURL("repos/base");
|
||||
mirror.loadMirrorRepositoryURL("repos/mirror");
|
||||
//mirror.synchronize();
|
||||
mirror.createHooks();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SVNException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
new ConnectOrCreateWindow("SvnMirror");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.svn.utils.mirror.app;
|
||||
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
import org.tmatesoft.svn.core.SVNPropertyValue;
|
||||
import org.tmatesoft.svn.core.SVNURL;
|
||||
import org.tmatesoft.svn.core.*;
|
||||
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
|
||||
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
|
||||
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
|
||||
@@ -10,11 +8,14 @@ import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
|
||||
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
||||
import org.tmatesoft.svn.core.wc.SVNClientManager;
|
||||
import org.tmatesoft.svn.core.wc.SVNRevision;
|
||||
import org.tmatesoft.svn.core.wc.SVNWCUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* SvnMirror
|
||||
@@ -48,32 +49,34 @@ public final class Mirror {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void createBaseRepo(String name) throws SVNException {
|
||||
public SVNURL createBaseRepo(String name) throws SVNException {
|
||||
baseRepositoryURL = createRepo(name);
|
||||
return baseRepositoryURL;
|
||||
}
|
||||
|
||||
public void createMirrorRepo(String name) throws SVNException {
|
||||
public SVNURL createMirrorRepo(String name) throws SVNException {
|
||||
mirrorRepositoryURL = createRepo(name);
|
||||
return mirrorRepositoryURL;
|
||||
}
|
||||
|
||||
public void loadBaseRepostory(SVNURL url) throws SVNException {
|
||||
public void loadBaseRepository(SVNURL url) throws SVNException {
|
||||
baseRepository = SVNRepositoryFactory.create(url);
|
||||
//authenticate(mirrorRepository, name, password);
|
||||
}
|
||||
|
||||
public void loadMirrorRepository(SVNURL url) throws SVNException {
|
||||
mirrorRepository = SVNRepositoryFactory.create(url);
|
||||
//authenticate(mirrorRepository, name, password);
|
||||
}
|
||||
|
||||
public void loadBaseRepositoryURL(String url) throws SVNException {
|
||||
baseRepositoryURL = SVNURL.fromFile(new File(url));
|
||||
loadBaseRepository(baseRepositoryURL);
|
||||
}
|
||||
|
||||
public void loadMirrorRepositoryURL(String url) throws SVNException {
|
||||
mirrorRepositoryURL = SVNURL.fromFile(new File(url));
|
||||
}
|
||||
|
||||
public void loadMirrorRepostory(SVNURL url, String name, String password) throws SVNException {
|
||||
mirrorRepository = SVNRepositoryFactory.create(url);
|
||||
//authenticate(mirrorRepository, name, password);
|
||||
|
||||
loadMirrorRepository(mirrorRepositoryURL);
|
||||
}
|
||||
|
||||
public void authenticate(SVNRepository repository, String name, String password) {
|
||||
@@ -82,18 +85,6 @@ public final class Mirror {
|
||||
repository.setAuthenticationManager(authManager);
|
||||
}
|
||||
|
||||
private void setupSvnRepositoryFactory() {
|
||||
SVNRepositoryFactoryImpl.setup();
|
||||
}
|
||||
|
||||
private void setupHttpRepositoryFactory() {
|
||||
DAVRepositoryFactory.setup();
|
||||
}
|
||||
|
||||
private void setupFileRepositoryFactory() {
|
||||
FSRepositoryFactory.setup();
|
||||
}
|
||||
|
||||
private void initializeRepository(SVNURL fromRepos, SVNURL toRepos) throws SVNException {
|
||||
svnClientManager.getAdminClient().doInitialize(baseRepositoryURL, mirrorRepositoryURL);
|
||||
}
|
||||
@@ -113,7 +104,7 @@ public final class Mirror {
|
||||
public void createHooks() throws IOException {
|
||||
String text = "#!/bin/sh \n" +
|
||||
"svnsync --non-interactive sync " +
|
||||
"file://"+mirrorRepositoryURL.getURIEncodedPath();
|
||||
"file://" + mirrorRepositoryURL.getURIEncodedPath();
|
||||
File file = new File(baseRepositoryURL.getURIEncodedPath() + "/hooks/post-commit");
|
||||
file.createNewFile();
|
||||
file.setExecutable(true);
|
||||
@@ -128,4 +119,101 @@ public final class Mirror {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void createRepo(String name, CreateRepoInt createRepoInt) {
|
||||
try {
|
||||
SVNURL svnURL = createRepo(name);
|
||||
createRepoInt.onRepoCreated(svnURL);
|
||||
} catch (SVNException e) {
|
||||
createRepoInt.onRepoCreationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void createMirrorRepo(String name, CreateRepoInt createRepoInt) {
|
||||
try {
|
||||
SVNURL svnURL = createMirrorRepo(name);
|
||||
createRepoInt.onRepoCreated(svnURL);
|
||||
} catch (SVNException e) {
|
||||
createRepoInt.onRepoCreationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
long getRevison(SVNRepository repository) throws SVNException {
|
||||
return repository.getLatestRevision();
|
||||
}
|
||||
|
||||
long getMirrorRevison() throws SVNException {
|
||||
return mirrorRepository.getLatestRevision();
|
||||
}
|
||||
|
||||
long getBaseRevison() throws SVNException {
|
||||
return baseRepository.getLatestRevision();
|
||||
}
|
||||
|
||||
boolean isSynced() throws SVNException {
|
||||
return getBaseRevison() == getMirrorRevison();
|
||||
}
|
||||
|
||||
public String listEntries(String path) throws SVNException {
|
||||
Collection entries = baseRepository.getDir(path, -1, null, (Collection) null);
|
||||
Iterator iterator = entries.iterator();
|
||||
String output = "";
|
||||
while (iterator.hasNext()) {
|
||||
SVNDirEntry entry = (SVNDirEntry) iterator.next();
|
||||
output += ("/" + (path.equals("") ? "" : path + "/") + entry.getName() +
|
||||
" ( author: '" + entry.getAuthor() + "'; revision: " + entry.getRevision() +
|
||||
"; date: " + entry.getDate() + ")\n");
|
||||
if (entry.getKind() == SVNNodeKind.DIR) {
|
||||
listEntries((path.equals("")) ? entry.getName() : path + "/" + entry.getName());
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
String getHistory(long startRevision, long endRevision) throws SVNException {
|
||||
String history = "";
|
||||
Collection logEntries = null;
|
||||
|
||||
logEntries = baseRepository.log(new String[]{""}, null, startRevision, endRevision, true, true);
|
||||
for (Iterator entries = logEntries.iterator(); entries.hasNext(); ) {
|
||||
SVNLogEntry logEntry = (SVNLogEntry) entries.next();
|
||||
history+="\n---------------------------------------------\n";
|
||||
history+="\nrevision: " + logEntry.getRevision();
|
||||
history+="\nauthor: " + logEntry.getAuthor();
|
||||
history+="\ndate: " + logEntry.getDate();
|
||||
history+="\nlog message: " + logEntry.getMessage();
|
||||
if (logEntry.getChangedPaths().size() > 0) {
|
||||
history+="\nchanged paths:";
|
||||
Set changedPathsSet = logEntry.getChangedPaths().keySet();
|
||||
|
||||
for (Iterator changedPaths = changedPathsSet.iterator(); changedPaths.hasNext(); ) {
|
||||
SVNLogEntryPath entryPath = (SVNLogEntryPath) logEntry.getChangedPaths().get(changedPaths.next());
|
||||
String a=" "
|
||||
+ entryPath.getType()
|
||||
+ " "
|
||||
+ entryPath.getPath()
|
||||
+ ((entryPath.getCopyPath() != null) ? " (from "
|
||||
+ entryPath.getCopyPath() + " revision "
|
||||
+ entryPath.getCopyRevision() + ")" : "");
|
||||
history+=a;
|
||||
}
|
||||
}
|
||||
}
|
||||
return history;
|
||||
}
|
||||
|
||||
String getHistory() throws SVNException {
|
||||
return getHistory(0,-1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws SVNException {
|
||||
Mirror mirror = Mirror.getInstance();
|
||||
mirror.loadBaseRepositoryURL("repos/base/");
|
||||
mirror.loadMirrorRepositoryURL("repos/mirror");
|
||||
|
||||
System.out.println(mirror.listEntries(""));
|
||||
System.out.println(mirror.getHistory(1,1));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.svn.utils.mirror.app.ssh;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by mar on 14.06.15.
|
||||
*/
|
||||
public class SshConnect {
|
||||
|
||||
private Session session;
|
||||
|
||||
public SshConnect(String user, String password, String host) throws JSchException {
|
||||
JSch jSch = new JSch();
|
||||
session = jSch.getSession(user, host);
|
||||
session.setPassword(password);
|
||||
java.util.Properties config = new java.util.Properties();
|
||||
config.put("StrictHostKeyChecking", "no");
|
||||
session.setConfig(config);
|
||||
}
|
||||
|
||||
public List<String> executeCommands(List<String> commands) {
|
||||
List<String> result = new ArrayList<>(commands.size());
|
||||
try {
|
||||
|
||||
session.connect();
|
||||
for (String command : commands) {
|
||||
Channel channel = session.openChannel("exec");
|
||||
result.add(execute(channel, command));
|
||||
|
||||
}
|
||||
session.disconnect();
|
||||
|
||||
|
||||
} catch (JSchException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e.getCause().getMessage());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return session.isConnected();
|
||||
}
|
||||
|
||||
public String execute(Channel channel, String command) throws JSchException, IOException {
|
||||
((ChannelExec) channel).setCommand(command);
|
||||
channel.setInputStream(null);
|
||||
((ChannelExec) channel).setErrStream(System.err);
|
||||
InputStream in = channel.getInputStream();
|
||||
channel.connect();
|
||||
byte[] tmp = new byte[1024];
|
||||
String returnMessage = null;
|
||||
while (true) {
|
||||
while (in.available() > 0) {
|
||||
int i = in.read(tmp, 0, 1024);
|
||||
if (i < 0) break;
|
||||
returnMessage += new String(tmp, 0, i);
|
||||
}
|
||||
if (channel.isClosed()) {
|
||||
if (in.available() > 0) continue;
|
||||
System.out.println("exit-status: " + channel.getExitStatus());
|
||||
break;
|
||||
}
|
||||
}
|
||||
channel.disconnect();
|
||||
return returnMessage;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
session.disconnect();
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
return session;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.svn.utils.mirror.gui.enums;
|
||||
|
||||
/**
|
||||
* SvnMirror
|
||||
* Created by Marcin on 2015-06-16.
|
||||
*/
|
||||
public enum RepoAction {
|
||||
CONNECT_TO_EXISTING_REPO_MIRROR,
|
||||
CREATE_NEW_REPO_MIRROR
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.svn.utils.mirror.gui.enums;
|
||||
|
||||
/**
|
||||
* SvnMirror
|
||||
* Created by Marcin on 2015-06-16.
|
||||
*/
|
||||
public enum RepositoryType {
|
||||
LOCAL,
|
||||
REMOTE
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.svn.utils.mirror.gui.enums;
|
||||
|
||||
/**
|
||||
* SvnMirror
|
||||
* Created by Marcin on 2015-06-16.
|
||||
*/
|
||||
public enum SynchronizationStatus {
|
||||
SYNCHRONIZED,
|
||||
NOT_SYNCHRONIZED,
|
||||
WAITING_FOR_FEEDBACK;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this == WAITING_FOR_FEEDBACK) {
|
||||
return "WAITING";
|
||||
} else {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.svn.utils.mirror.gui.main.ConnectOrCreateWindow">
|
||||
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="15" left="15" bottom="15" right="15"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="ee3e2">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="97acd" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="SvnMirror - tool for establishing SVN repo mirroring"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c6306" class="javax.swing.JButton" binding="connectWithExistingButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Attach to existing configuration"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a94e1" class="javax.swing.JButton" binding="createMirrorButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Create mirroring"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.svn.utils.mirror.gui.main;
|
||||
|
||||
import com.svn.utils.mirror.gui.enums.RepoAction;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* SvnMirror
|
||||
* Created by Marcin on 2015-06-16.
|
||||
*/
|
||||
public class ConnectOrCreateWindow extends JFrame {
|
||||
private JButton connectWithExistingButton;
|
||||
private JButton createMirrorButton;
|
||||
private JPanel rootPanel;
|
||||
|
||||
public ConnectOrCreateWindow(String title) throws HeadlessException {
|
||||
super(title);
|
||||
initAndShowMainWindow();
|
||||
addListeners();
|
||||
}
|
||||
|
||||
private void addListeners() {
|
||||
createMirrorButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new MainWindow("Create mirroring", RepoAction.CREATE_NEW_REPO_MIRROR);
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
connectWithExistingButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new MainWindow("Attach to existing configuration", RepoAction.CONNECT_TO_EXISTING_REPO_MIRROR);
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initAndShowMainWindow() {
|
||||
setContentPane(rootPanel);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,164 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.svn.utils.mirror.gui.main.MainWindow">
|
||||
<grid id="27dc6" binding="rootPanel" layout-manager="FormLayout">
|
||||
<rowspec value="center:d:noGrow"/>
|
||||
<rowspec value="center:max(d;4px):noGrow"/>
|
||||
<rowspec value="top:4dlu:noGrow"/>
|
||||
<rowspec value="center:max(d;4px):noGrow"/>
|
||||
<colspec value="fill:d:grow"/>
|
||||
<rowspec value="top:4dlu:noGrow"/>
|
||||
<rowspec value="center:max(d;4px):noGrow"/>
|
||||
<rowspec value="top:4dlu:noGrow"/>
|
||||
<rowspec value="center:max(d;4px):noGrow"/>
|
||||
<rowspec value="top:4dlu:noGrow"/>
|
||||
<rowspec value="center:max(d;4px):noGrow"/>
|
||||
<rowspec value="top:4dlu:noGrow"/>
|
||||
<rowspec value="center:d:grow"/>
|
||||
<rowspec value="top:4dlu:noGrow"/>
|
||||
<rowspec value="center:d:grow"/>
|
||||
<colspec value="fill:363px:grow"/>
|
||||
<colspec value="left:4dlu:noGrow"/>
|
||||
<colspec value="fill:d:noGrow"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
<xy x="20" y="20" width="500" height="435"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="4f73b" class="javax.swing.JTextPane" binding="logTextPane">
|
||||
<scrollpane id="b8f99">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="50"/>
|
||||
</grid>
|
||||
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<forms defaultalign-horz="false" defaultalign-vert="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="ada03" class="javax.swing.JButton" binding="createRepoButton">
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="4f73b" class="javax.swing.JTextPane" binding="logTextPane">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="logs"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<grid id="c9d20" binding="rootServerLoginPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="15" left="15" bottom="15" right="15"/>
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<forms/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none" title="Login Data"/>
|
||||
<children>
|
||||
<component id="f3976" class="javax.swing.JTextField" binding="loginTextFields">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="SVN user login"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ae73" class="javax.swing.JPasswordField" binding="passwordField">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="password"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<scrollpane id="19c4a">
|
||||
<constraints>
|
||||
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<forms defaultalign-horz="false" defaultalign-vert="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="88417" class="javax.swing.JEditorPane" binding="detailsPane">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="details"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<grid id="7dd0b" binding="synchronizationStatusPanel" layout-manager="CardLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<forms top="5" left="5" bottom="5" right="5" defaultalign-vert="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="2412b" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="15" left="15" bottom="15" right="15"/>
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<forms/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none" title="Repository paths"/>
|
||||
<children>
|
||||
<component id="ddc3e" class="javax.swing.JTextField" binding="sourceRepositoryPathTextField">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Source repository path"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="703e0" class="javax.swing.JTextField" binding="destinationRepositoryPathTextField" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Destination repository path"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="ada03" class="javax.swing.JButton" binding="mirrorButton">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<forms top="0" left="15" bottom="0" right="15"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Mirror"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="6a575" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="5" left="15" bottom="5" right="15"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<forms/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none" title="Repository type"/>
|
||||
<children>
|
||||
<component id="3fbfa" class="javax.swing.JComboBox" binding="repositoryTypeComboBox">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="2d020" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<forms/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Create repo"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ddc3e" class="javax.swing.JTextField" binding="nameTextField" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
<forms defaultalign-horz="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="name"/>
|
||||
<text value="Synchronization:"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
|
||||
@@ -2,7 +2,12 @@ package com.svn.utils.mirror.gui.main;
|
||||
|
||||
import com.svn.utils.mirror.app.CreateRepoInt;
|
||||
import com.svn.utils.mirror.app.Mirror;
|
||||
import com.svn.utils.mirror.gui.enums.RepoAction;
|
||||
import com.svn.utils.mirror.gui.enums.RepositoryType;
|
||||
import com.svn.utils.mirror.gui.enums.SynchronizationStatus;
|
||||
import com.svn.utils.mirror.gui.logger.StatusLogger;
|
||||
import com.svn.utils.mirror.gui.model.RepositoryModel;
|
||||
import com.svn.utils.mirror.gui.view.SynchronizationStatusComponent;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
import org.tmatesoft.svn.core.SVNURL;
|
||||
|
||||
@@ -10,6 +15,8 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
/**
|
||||
* SvnMirror
|
||||
@@ -17,33 +24,87 @@ import java.awt.event.ActionListener;
|
||||
*/
|
||||
public class MainWindow extends JFrame implements CreateRepoInt {
|
||||
private JPanel rootPanel;
|
||||
private JButton createRepoButton;
|
||||
private JButton mirrorButton;
|
||||
private JTextPane logTextPane;
|
||||
private JTextField nameTextField;
|
||||
private JTextField sourceRepositoryPathTextField;
|
||||
private JTextField destinationRepositoryPathTextField;
|
||||
private JComboBox repositoryTypeComboBox;
|
||||
private JTextField loginTextFields;
|
||||
private JPasswordField passwordField;
|
||||
private JPanel rootServerLoginPanel;
|
||||
private JEditorPane detailsPane;
|
||||
private JPanel synchronizationStatusPanel;
|
||||
private StatusLogger statusLogger;
|
||||
private RepoAction repoAction;
|
||||
private SynchronizationStatusComponent synchronizationStatusComponent;
|
||||
private Mirror mirror;
|
||||
|
||||
public MainWindow(String title) throws HeadlessException {
|
||||
public MainWindow(String title, RepoAction repoAction) throws HeadlessException {
|
||||
super(title);
|
||||
statusLogger = new StatusLogger(logTextPane);
|
||||
initAndShowMainWindow();
|
||||
this.repoAction = repoAction;
|
||||
initView();
|
||||
initFormBasedOnRepoAction();
|
||||
addListeners();
|
||||
mirror = Mirror.getInstance();
|
||||
}
|
||||
|
||||
private void addListeners() {
|
||||
createRepoButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//Mirror.createRepo(nameTextField.getText(), MainWindow.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initAndShowMainWindow() {
|
||||
private void initView() {
|
||||
setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||
setContentPane(rootPanel);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
pack();
|
||||
setVisible(true);
|
||||
initSynchronizationStatusComponent();
|
||||
initRemoteOrLocalComboBox();
|
||||
}
|
||||
|
||||
private void initRemoteOrLocalComboBox() {
|
||||
DefaultComboBoxModel<RepositoryModel> repositoryTypeComboBoxModel = new DefaultComboBoxModel<RepositoryModel>();
|
||||
repositoryTypeComboBoxModel.addElement(new RepositoryModel(RepositoryType.REMOTE));
|
||||
repositoryTypeComboBoxModel.addElement(new RepositoryModel(RepositoryType.LOCAL));
|
||||
repositoryTypeComboBox.setModel(repositoryTypeComboBoxModel);
|
||||
|
||||
}
|
||||
|
||||
private void initSynchronizationStatusComponent() {
|
||||
synchronizationStatusComponent = new SynchronizationStatusComponent();
|
||||
synchronizationStatusComponent.setSynchronizationStatus(SynchronizationStatus.WAITING_FOR_FEEDBACK);
|
||||
synchronizationStatusPanel.add(synchronizationStatusComponent);
|
||||
}
|
||||
|
||||
private void initFormBasedOnRepoAction() {
|
||||
// @TODO hide & show GUI parts
|
||||
switch (repoAction) {
|
||||
case CONNECT_TO_EXISTING_REPO_MIRROR:
|
||||
mirrorButton.setText("Attach");
|
||||
break;
|
||||
case CREATE_NEW_REPO_MIRROR:
|
||||
break;
|
||||
}
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void addListeners() {
|
||||
mirrorButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
mirror.createRepo(sourceRepositoryPathTextField.getText(), MainWindow.this);
|
||||
}
|
||||
});
|
||||
|
||||
repositoryTypeComboBox.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
if (((RepositoryModel) e.getItem()).getRepositoryType() == RepositoryType.LOCAL) {
|
||||
rootServerLoginPanel.setVisible(false);
|
||||
} else {
|
||||
rootServerLoginPanel.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.svn.utils.mirror.gui.model;
|
||||
|
||||
import com.svn.utils.mirror.gui.enums.RepositoryType;
|
||||
|
||||
/**
|
||||
* SvnMirror
|
||||
* Created by Marcin on 2015-06-16.
|
||||
*/
|
||||
public class RepositoryModel {
|
||||
private RepositoryType repositoryType;
|
||||
|
||||
public RepositoryModel(RepositoryType repositoryType) {
|
||||
this.repositoryType = repositoryType;
|
||||
}
|
||||
|
||||
public RepositoryType getRepositoryType() {
|
||||
return repositoryType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return repositoryType.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.svn.utils.mirror.gui.view;
|
||||
|
||||
import com.svn.utils.mirror.gui.enums.SynchronizationStatus;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
/**
|
||||
* SvnMirror
|
||||
* Created by Marcin on 2015-06-16.
|
||||
*/
|
||||
public class SynchronizationStatusComponent extends JComponent {
|
||||
private SynchronizationStatus synchronizationStatus;
|
||||
|
||||
public void setSynchronizationStatus(SynchronizationStatus synchronizationStatus) {
|
||||
this.synchronizationStatus = synchronizationStatus;
|
||||
repaint();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
switch (synchronizationStatus) {
|
||||
case SYNCHRONIZED:
|
||||
g.setColor(Color.GREEN);
|
||||
break;
|
||||
case NOT_SYNCHRONIZED:
|
||||
g.setColor(Color.RED);
|
||||
break;
|
||||
case WAITING_FOR_FEEDBACK:
|
||||
g.setColor(Color.YELLOW);
|
||||
break;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
Rectangle2D.Double circle = new Rectangle2D.Double(getX(),
|
||||
getY(),
|
||||
getWidth(),
|
||||
getHeight());
|
||||
g2d.fill(circle);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawString(synchronizationStatus.toString(), getX(), getY() + getHeight() / 2);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user