10 changed files with 288 additions and 65 deletions

No files matched your search

+1 -1
View File
@@ -1,3 +1,3 @@
# SvnMirror
Using git-flow. Go to develop branch.
Java application which creates two svn repositories and sets up mirroring between them.
+2
View File
@@ -10,5 +10,7 @@ repositories {
}
dependencies {
compile 'org.tmatesoft.svnkit:svnkit:1.8.10'
compile 'com.jgoodies:forms:1.2.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
@@ -1,6 +1,8 @@
package com.svn.utils.mirror;
import com.svn.utils.mirror.gui.MainWindow;
import com.svn.utils.mirror.app.Mirror;
import com.svn.utils.mirror.gui.main.MainWindow;
import org.tmatesoft.svn.core.SVNException;
/**
* SvnMirror
@@ -8,6 +10,17 @@ import com.svn.utils.mirror.gui.MainWindow;
*/
public class SvnMirror {
public static void main(String[] args) {
new MainWindow("HelloWorldSwing");
//new MainWindow("HelloWorldSwing");
Mirror mirror = Mirror.getInstance();
try {
//mirror.createBaseRepo("base");
//mirror.createMirrorRepo("mirror");
mirror.loadBaseRepositoryURL("repos/base");
mirror.loadMirrorRepositoryURL("repos/mirror");
mirror.synchronize();
} catch (SVNException e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,13 @@
package com.svn.utils.mirror.app;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
/**
* SvnMirror
* Created by Marcin on 2015-06-12.
*/
public interface CreateRepoInt {
void onRepoCreated(SVNURL svnurl);
void onRepoCreationException(SVNException e);
}
@@ -0,0 +1,112 @@
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.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
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.SVNWCUtil;
import java.io.File;
import java.util.Iterator;
import java.util.Map;
/**
* SvnMirror
* Created by Marcin on 2015-06-12.
*/
public final class Mirror {
private SVNRepository baseRepository;
private SVNURL baseRepositoryURL;
private SVNRepository mirrorRepository;
private SVNURL mirrorRepositoryURL;
private SVNClientManager svnClientManager;
private static Mirror mirror;
public static Mirror getInstance() {
if (mirror == null) {
mirror = new Mirror();
mirror.init();
}
return mirror;
}
private Mirror() {
}
public void init() {
svnClientManager = SVNClientManager.newInstance();
}
public SVNURL createRepo(String name) throws SVNException {
SVNURL url = SVNRepositoryFactory.createLocalRepository(new File("repos/" + name), true, true);
return url;
}
public void createBaseRepo(String name) throws SVNException {
baseRepositoryURL = createRepo(name);
}
public void createMirrorRepo(String name) throws SVNException {
mirrorRepositoryURL = createRepo(name);
}
public void loadBaseRepostory(SVNURL url) throws SVNException {
baseRepository = SVNRepositoryFactory.create(url);
//authenticate(mirrorRepository, name, password);
}
public void loadBaseRepositoryURL(String url) throws SVNException {
baseRepositoryURL = SVNURL.fromFile(new File(url));
}
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);
}
public void authenticate(SVNRepository repository, String name, String password) {
ISVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager(name, password);
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);
}
public void initializeRepository() throws SVNException {
initializeRepository(baseRepositoryURL, mirrorRepositoryURL);
}
public void synchronize(SVNURL fromRepos, SVNURL toRepos) throws SVNException {
svnClientManager.getAdminClient().doSynchronize(toRepos);
}
public void synchronize() throws SVNException {
synchronize(baseRepositoryURL, mirrorRepositoryURL);
}
}
@@ -1,39 +0,0 @@
<?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.MainWindow">
<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="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="24bb7">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="5dae">
<constraints>
<grid row="1" column="0" 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="2b3b0" class="javax.swing.JButton" binding="helloButton" default-binding="true">
<constraints>
<grid row="2" column="1" 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="Hello"/>
</properties>
</component>
<component id="a2a37" class="javax.swing.JButton" binding="button1" default-binding="true">
<constraints>
<grid row="1" column="1" 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="Button"/>
</properties>
</component>
</children>
</grid>
</form>
@@ -1,23 +0,0 @@
package com.svn.utils.mirror.gui;
import javax.swing.*;
import java.awt.*;
/**
* SvnMirror
* Created by Marcin on 2015-06-12.
*/
public class MainWindow extends JFrame {
private JButton helloButton;
private JButton button1;
private JPanel rootPanel;
public MainWindow(String title) throws HeadlessException {
super(title);
setContentPane(rootPanel);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
}
@@ -0,0 +1,40 @@
package com.svn.utils.mirror.gui.logger;
import javax.swing.*;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import java.awt.*;
/**
* SvnMirror
* Created by Marcin on 2015-06-12.
*/
public class StatusLogger {
private JTextPane logContainer;
private void appendToPane(JTextPane jTextPane, String message, Color color) {
StyleContext styleContext = StyleContext.getDefaultStyleContext();
AttributeSet attributeSet = styleContext.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
attributeSet = styleContext.addAttribute(attributeSet, StyleConstants.FontFamily, "Lucida Console");
attributeSet = styleContext.addAttribute(attributeSet, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
int len = jTextPane.getDocument().getLength();
jTextPane.setCaretPosition(len);
jTextPane.setCharacterAttributes(attributeSet, false);
jTextPane.replaceSelection(message);
}
public StatusLogger(JTextPane logContainer) {
this.logContainer = logContainer;
}
public void logError(String message) {
appendToPane(logContainer, message, Color.RED);
}
public void logSuccess(String message) {
appendToPane(logContainer, message, Color.GREEN);
}
}
@@ -0,0 +1,47 @@
<?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="top:4dlu:noGrow"/>
<rowspec value="center:max(d;4px):noGrow"/>
<colspec value="fill:d:grow"/>
<colspec value="left:4dlu:noGrow"/>
<colspec value="fill:d:noGrow"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="4f73b" class="javax.swing.JTextPane" binding="logTextPane">
<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>
<forms defaultalign-horz="false" defaultalign-vert="false"/>
</constraints>
<properties/>
</component>
<component id="ada03" class="javax.swing.JButton" binding="createRepoButton">
<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"/>
<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"/>
</properties>
</component>
</children>
</grid>
</form>
@@ -0,0 +1,58 @@
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.logger.StatusLogger;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* SvnMirror
* Created by Marcin on 2015-06-12.
*/
public class MainWindow extends JFrame implements CreateRepoInt {
private JPanel rootPanel;
private JButton createRepoButton;
private JTextPane logTextPane;
private JTextField nameTextField;
private StatusLogger statusLogger;
public MainWindow(String title) throws HeadlessException {
super(title);
statusLogger = new StatusLogger(logTextPane);
initAndShowMainWindow();
addListeners();
}
private void addListeners() {
createRepoButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//Mirror.createRepo(nameTextField.getText(), MainWindow.this);
}
});
}
private void initAndShowMainWindow() {
setExtendedState(JFrame.MAXIMIZED_BOTH);
setContentPane(rootPanel);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
@Override
public void onRepoCreated(SVNURL svnurl) {
statusLogger.logSuccess("Repo created: " + svnurl.getPath());
}
@Override
public void onRepoCreationException(SVNException e) {
statusLogger.logError("Repo creation failed: " + e.getMessage());
}
}