Skip to content

Commit

Permalink
Merged #28 "Replace JCommander with args4j"
Browse files Browse the repository at this point in the history
  • Loading branch information
gitblit committed Mar 27, 2014
2 parents 03a0310 + 50380b3 commit 4a70ea7
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .classpath
Expand Up @@ -10,7 +10,6 @@
<classpathentry kind="lib" path="ext/dagger-compiler-1.1.0.jar" sourcepath="ext/src/dagger-compiler-1.1.0.jar" />
<classpathentry kind="lib" path="ext/javawriter-2.1.1.jar" sourcepath="ext/src/javawriter-2.1.1.jar" />
<classpathentry kind="lib" path="ext/annotations-12.0.jar" sourcepath="ext/src/annotations-12.0.jar" />
<classpathentry kind="lib" path="ext/jcommander-1.17.jar" sourcepath="ext/src/jcommander-1.17.jar" />
<classpathentry kind="lib" path="ext/log4j-1.2.17.jar" sourcepath="ext/src/log4j-1.2.17.jar" />
<classpathentry kind="lib" path="ext/slf4j-api-1.6.6.jar" sourcepath="ext/src/slf4j-api-1.6.6.jar" />
<classpathentry kind="lib" path="ext/slf4j-log4j12-1.6.6.jar" sourcepath="ext/src/slf4j-log4j12-1.6.6.jar" />
Expand Down Expand Up @@ -73,6 +72,7 @@
<classpathentry kind="lib" path="ext/jna-3.5.0.jar" sourcepath="ext/src/jna-3.5.0.jar" />
<classpathentry kind="lib" path="ext/guava-13.0.1.jar" sourcepath="ext/src/guava-13.0.1.jar" />
<classpathentry kind="lib" path="ext/libpam4j-1.7.jar" sourcepath="ext/src/libpam4j-1.7.jar" />
<classpathentry kind="lib" path="ext/args4j-2.0.26.jar" sourcepath="ext/src/args4j-2.0.26.jar" />
<classpathentry kind="lib" path="ext/jedis-2.3.1.jar" sourcepath="ext/src/jedis-2.3.1.jar" />
<classpathentry kind="lib" path="ext/commons-pool2-2.0.jar" sourcepath="ext/src/commons-pool2-2.0.jar" />
<classpathentry kind="lib" path="ext/junit-4.11.jar" sourcepath="ext/src/junit-4.11.jar" />
Expand Down
24 changes: 8 additions & 16 deletions NOTICE
Expand Up @@ -151,22 +151,6 @@ JUnit

http://junit.org

---------------------------------------------------------------------------
ant-googlecode
---------------------------------------------------------------------------
ant-googlecode, released under the
New BSD License

http://code.google.com/p/ant-googlecode

---------------------------------------------------------------------------
GenJar
---------------------------------------------------------------------------
GenJar, released under the
Apache Software License, Version 1.1.

http://genjar.sourceforge.net

---------------------------------------------------------------------------
Fancybox image viewer
---------------------------------------------------------------------------
Expand Down Expand Up @@ -342,3 +326,11 @@ Jedis
MIT license

https://github.com/xetorthio/jedis

---------------------------------------------------------------------------
args4j
---------------------------------------------------------------------------
args4j, release under the
Apache License 2.0

http://args4j.kohsuke.org
2 changes: 1 addition & 1 deletion build.moxie
Expand Up @@ -128,7 +128,6 @@ dependencies:
- compile 'com.squareup.dagger:dagger-compiler:1.1.0' :war optional apt
# Standard dependencies
- compile 'com.intellij:annotations:12.0' :war
- compile 'com.beust:jcommander:1.17' :fedclient :authority
- compile 'log4j:log4j:1.2.17' :war :fedclient :authority
- compile 'org.slf4j:slf4j-api:1.6.6' :war :fedclient :authority
- compile 'org.slf4j:slf4j-log4j12:1.6.6' :war :fedclient :authority
Expand Down Expand Up @@ -169,6 +168,7 @@ dependencies:
- compile 'org.freemarker:freemarker:2.3.19' :war
- compile 'com.github.dblock.waffle:waffle-jna:1.5' :war
- compile 'org.kohsuke:libpam4j:1.7' :war
- compile 'args4j:args4j:2.0.26' :war :fedclient :authority
- compile 'commons-codec:commons-codec:1.7' :war
- compile 'redis.clients:jedis:2.3.1' :war
- test 'junit'
Expand Down
22 changes: 11 additions & 11 deletions gitblit.iml
Expand Up @@ -68,17 +68,6 @@
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="jcommander-1.17.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/ext/jcommander-1.17.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/ext/src/jcommander-1.17.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="log4j-1.2.17.jar">
<CLASSES>
Expand Down Expand Up @@ -757,6 +746,17 @@
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="args4j-2.0.26.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/ext/args4j-2.0.26.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/ext/src/args4j-2.0.26.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="jedis-2.3.1.jar">
<CLASSES>
Expand Down
10 changes: 7 additions & 3 deletions releases.moxie
Expand Up @@ -13,11 +13,15 @@ r22: {
- Repository mailing lists could not be reset from the Edit Repository page (issue-399)
- Ensure the Lucene ticket index is updated on repository deletion.
changes:
- Option to allow LDAP users to directly authenticate without performing LDAP searches
- Option to allow LDAP users to directly authenticate without performing LDAP searches (pr-162))
- Replace JCommander with args4j to be consistent with other tools (ticket-28)
additions:
- Added a French translation
dependencyChanges: ~
- Added a French translation (pr-163)
dependencyChanges:
- args4j 2.0.26
contributors:
- James Moger
- David Ostrovsky
- Johann Ollivier-Lapeyre
- Jeremie Brebec
settings:
Expand Down
30 changes: 14 additions & 16 deletions src/main/java/com/gitblit/AddIndexedBranch.java
Expand Up @@ -28,11 +28,10 @@
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.util.FS;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
import com.gitblit.models.RefModel;
import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.JGitUtils;
Expand All @@ -48,12 +47,12 @@ public class AddIndexedBranch {

public static void main(String... args) {
Params params = new Params();
JCommander jc = new JCommander(params);
CmdLineParser parser = new CmdLineParser(params);
try {
jc.parse(args);
} catch (ParameterException t) {
parser.parseArgument(args);
} catch (CmdLineException t) {
System.err.println(t.getMessage());
jc.usage();
parser.printUsage(System.out);
return;
}

Expand Down Expand Up @@ -95,7 +94,7 @@ public static void main(String... args) {
Set<String> indexedBranches = new LinkedHashSet<String>();

// add all local branches to index
if(params.addAllLocalBranches) {
if (params.addAllLocalBranches) {
List<RefModel> list = JGitUtils.getLocalBranches(repository, true, -1);
for (RefModel refModel : list) {
System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", refModel.getName(), repo));
Expand Down Expand Up @@ -129,21 +128,20 @@ public static void main(String... args) {


/**
* JCommander Parameters class for AddIndexedBranch.
* Parameters class for AddIndexedBranch.
*/
@Parameters(separators = " ")
private static class Params {

@Parameter(names = { "--repositoriesFolder" }, description = "The root repositories folder ", required = true)
@Option(name = "--repositoriesFolder", usage = "The root repositories folder ", required = true, metaVar = "PATH")
public String folder;

@Parameter(names = { "--branch" }, description = "The branch to index", required = false)
@Option(name = "--branch", usage = "The branch to index", metaVar = "BRANCH")
public String branch = "default";

@Parameter(names = { "--skip" }, description = "Skip the named repository (simple fizzy matching is supported)", required = false)
@Option(name = "--skip", usage = "Skip the named repository (simple fizzy matching is supported)")
public List<String> exclusions = new ArrayList<String>();

@Parameter(names = { "--all-local-branches" }, description = "Add all local branches to index. If specified, the --branch parameter is not considered.", required = false)
public boolean addAllLocalBranches = false;
@Option(name = "--all-local-branches", usage = "Add all local branches to index. If specified, the --branch parameter is not considered.")
public boolean addAllLocalBranches;
}
}
43 changes: 19 additions & 24 deletions src/main/java/com/gitblit/FederationClient.java
Expand Up @@ -20,10 +20,10 @@
import java.util.Collection;
import java.util.List;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;

import com.gitblit.manager.FederationManager;
import com.gitblit.manager.GitblitManager;
import com.gitblit.manager.IGitblit;
Expand All @@ -47,11 +47,11 @@ public class FederationClient {

public static void main(String[] args) {
Params params = new Params();
JCommander jc = new JCommander(params);
CmdLineParser parser = new CmdLineParser(params);
try {
jc.parse(args);
} catch (ParameterException t) {
usage(jc, t);
parser.parseArgument(args);
} catch (CmdLineException t) {
usage(parser, t);
}

System.out.println("Gitblit Federation Client v" + Constants.getVersion() + " (" + Constants.getBuildDate() + ")");
Expand All @@ -77,7 +77,6 @@ public static void main(String[] args) {
model.token = params.token;
model.mirror = params.mirror;
model.bare = params.bare;
model.frequency = params.frequency;
model.folder = "";
registrations.add(model);
}
Expand Down Expand Up @@ -112,48 +111,44 @@ public void reschedule(FederationModel registration) {
System.exit(0);
}

private static void usage(JCommander jc, ParameterException t) {
private static void usage(CmdLineParser parser, CmdLineException t) {
System.out.println(Constants.getGitBlitVersion());
System.out.println();
if (t != null) {
System.out.println(t.getMessage());
System.out.println();
}

if (jc != null) {
jc.usage();
if (parser != null) {
parser.printUsage(System.out);
}
System.exit(0);
}

/**
* JCommander Parameters class for FederationClient.
* Parameters class for FederationClient.
*/
@Parameters(separators = " ")
private static class Params {

@Parameter(names = { "--registrations" }, description = "Gitblit Federation Registrations File", required = false)
@Option(name = "--registrations", usage = "Gitblit Federation Registrations File", metaVar = "FILE")
public String registrationsFile = "${baseFolder}/federation.properties";

@Parameter(names = { "--url" }, description = "URL of Gitblit instance to mirror from", required = false)
@Option(name = "--url", usage = "URL of Gitblit instance to mirror from", metaVar = "URL")
public String url;

@Parameter(names = { "--mirror" }, description = "Mirror repositories", required = false)
@Option(name = "--mirror", usage = "Mirror repositories")
public boolean mirror;

@Parameter(names = { "--bare" }, description = "Create bare repositories", required = false)
@Option(name = "--bare", usage = "Create bare repositories")
public boolean bare;

@Parameter(names = { "--token" }, description = "Federation Token", required = false)
@Option(name = "--token", usage = "Federation Token", metaVar = "TOKEN")
public String token;

@Parameter(names = { "--frequency" }, description = "Period to wait between pull attempts (requires --daemon)", required = false)
public String frequency = "60 mins";

@Parameter(names = { "--baseFolder" }, description = "Base folder for received data", required = false)
@Option(name = "--baseFolder", usage = "Base folder for received data", metaVar = "PATH")
public String baseFolder;

@Parameter(names = { "--repositoriesFolder" }, description = "Destination folder for cloned repositories", required = false)
@Option(name = "--repositoriesFolder", usage = "Destination folder for cloned repositories", metaVar = "PATH")
public String repositoriesFolder;

}
Expand Down

0 comments on commit 4a70ea7

Please sign in to comment.