krysalis-update/src/java/org/krysalis/depot/update/tool DownloaderTool.java,NONE,1.1 Tool.java,NONE,1.1 ConfigTool.java,NONE,1.1 ArtifactTool.java,NONE,1.1 RepositoryTool.java,NONE,1.1 RepositoriesTool.java,NONE,1.1
Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:06:45 +0000
| Newsgroups | gmane.comp.krysalis.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/tool
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/java/org/krysalis/depot/update/tool
Added Files:
DownloaderTool.java Tool.java ConfigTool.java
ArtifactTool.java RepositoryTool.java RepositoriesTool.java
Log Message:
Copied from the apache incubator.
--- NEW FILE: RepositoryTool.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krysalis.depot.update.tool;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import org.krysalis.depot.common.util.SystemUtils;
import org.krysalis.depot.common.util.cli.CommandLine;
import org.krysalis.depot.common.util.cli.Option;
import org.krysalis.depot.common.util.debug.DebugUtils;
import org.krysalis.depot.update.ArtifactInstance;
import org.krysalis.depot.update.ArtifactUpdater;
import org.krysalis.depot.update.ArtifactUpdaterFactory;
import org.krysalis.depot.update.Repository;
import org.krysalis.depot.update.artifact.ArtifactGroup;
import org.krysalis.depot.update.impl.ArtifactUpdaterContext;
import org.krysalis.depot.update.impl.RepositoryWrapper;
import org.krysalis.depot.update.repository.DefaultRepository;
import org.krysalis.depot.update.util.select.AllSelector;
/**
*/
public class RepositoryTool extends Tool {
private static Option l_repoOption = null;
private static Option l_groupOption = null;
private static Option l_listOption = null;
private static Option l_manifestOption = null;
private static Option l_cleanOption = null;
static {
l_repoOption = new Option("r", "repo", true, "Repository");
l_groupOption =
new Option("g", "group", true, "A specified artifact group");
l_listOption =
new Option("l", "list", false, "List artifacts or groups");
l_manifestOption = new Option("m", "manifest", false, "Show manifest");
l_cleanOption =
new Option(
"c",
"clean",
false,
"Clean 'older' resources, in a group");
}
protected String getTitle() {
return "Repository Tool";
}
protected void init() {
getOptions().addOption(l_repoOption);
getOptions().addOption(l_groupOption);
getOptions().addOption(l_listOption);
getOptions().addOption(l_manifestOption);
getOptions().addOption(l_cleanOption);
}
public void execute(CommandLine cmdline) throws Exception {
String repoId = cmdline.getMandatoryOptionValue(l_repoOption);
PrintWriter out = SystemUtils.getSystemOut();
DebugUtils.printSeparator();
DebugUtils.dump(cmdline);
Repository repository = DefaultRepository.getRepository(repoId);
ArtifactUpdater updater = ArtifactUpdaterFactory.getDefaultUpdater();
if (null != repository) {
RepositoryWrapper repo =
new RepositoryWrapper(
repository,
ArtifactUpdaterContext.getDefaultContext());
DebugUtils.printSeparator();
out.println("Repository: " + repo);
if ( isVerbose() )
DebugUtils.dump(repository);
if (cmdline.isSet(l_groupOption)) {
ArtifactGroup group =
new ArtifactGroup(
cmdline.getMandatoryOptionValue(l_groupOption));
if (cmdline.isSet(l_cleanOption)) {
updater.cleanRepository(repository, group);
}
else if (cmdline.isSet(l_manifestOption)) {
DebugUtils.printSeparator();
DebugUtils.dump(
repo.getManifest(group, AllSelector.getInstance()));
}
else {
DebugUtils.printSeparator();
List instances =
repo.listInstances(group, AllSelector.getInstance());
for (Iterator ii = instances.iterator(); ii.hasNext();) {
ArtifactInstance instance = (ArtifactInstance) ii.next();
out.println("Instance : " + instance);
if ( isVerbose() )
DebugUtils.dump(true,instance);
}
}
}
else if (cmdline.isSet(l_listOption)) {
DebugUtils.printSeparator();
DebugUtils.dump(repo.listGroups(AllSelector.getInstance()));
}
else {
List groups = repo.listGroups(AllSelector.getInstance());
for (Iterator i = groups.iterator(); i.hasNext();) {
ArtifactGroup group = (ArtifactGroup) i.next();
out.println("Group: " + group);
List instances =
repo.listInstances(group, AllSelector.getInstance());
for (Iterator ii = instances.iterator(); ii.hasNext();) {
ArtifactInstance instance = (ArtifactInstance) ii.next();
out.println("Instance : " + instance);
}
}
}
}
else {
out.println("No Such Repository: " + repoId);
}
}
public static void main(String[] args) {
(new RepositoryTool()).run(args);
}
}
--- NEW FILE: Tool.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.krysalis.depot.update.tool;
import java.io.PrintWriter;
import org.krysalis.depot.common.log.LogConstants;
import org.krysalis.depot.common.log.Logger;
import org.krysalis.depot.common.log.StandardLogListener;
import org.krysalis.depot.common.util.SystemUtils;
import org.krysalis.depot.common.util.cli.CommandLine;
import org.krysalis.depot.common.util.cli.CommandLineParser;
import org.krysalis.depot.common.util.cli.Option;
import org.krysalis.depot.common.util.cli.Options;
import org.krysalis.depot.common.util.cli.ParseException;
import org.krysalis.depot.common.util.debug.DebugUtils;
import org.krysalis.depot.update.config.UpdaterConfig;
import org.krysalis.depot.update.monitor.Monitor;
import org.krysalis.depot.update.monitor.StatisticsMonitor;
/**
* @author ajack
*/
public abstract class Tool {
private static Option l_debugOption = null;
private static Option l_verboseOption = null;
private static Option l_quietOption = null;
private static Option l_statsOption = null;
private static Option l_helpOption = null;
private static Option l_versionOption = null;
private static Options l_options = null;
private static boolean l_debug = false;
private static boolean l_verbose = false;
private static boolean l_quiet = false;
private static boolean l_help = false;
private static boolean l_version = false;
private static StatisticsMonitor l_statistics = null;
static {
l_versionOption = new Option("V", "version", false,
"print version, and exit");
l_helpOption = new Option("h", "help", false, "print help, and exit");
l_debugOption = new Option("d", "debug", false, "debug output");
l_verboseOption = new Option("v", "verbose", false, "verbose output");
l_quietOption = new Option("q", "quiet", false, "quiet output");
l_statsOption = new Option("s", "stats", false, "statistics output");
l_options = new Options();
l_options.addOption(l_helpOption);
l_options.addOption(l_versionOption);
l_options.addOption(l_debugOption);
l_options.addOption(l_verboseOption);
l_options.addOption(l_quietOption);
l_options.addOption(l_statsOption);
}
protected Options getOptions() {
return l_options;
}
protected PrintWriter getOutput() {
return SystemUtils.getSystemOut();
}
protected abstract String getTitle();
protected abstract void init();
protected void printVersion() {
String version = org.krysalis.depot.update.version.Version.getInstance().getLongVersion();
System.out.println("Apache Depot : " + getTitle() + " : " + version);
}
protected void printHelp() {
printVersion();
getOptions().display();
}
protected abstract void execute(CommandLine cmdline) throws Exception;
protected CommandLine parseCommandLine(String args[]) {
CommandLine cmdline = null;
try {
CommandLineParser parser = new CommandLineParser();
parser.setStrict(true);
cmdline = parser.parse(l_options, args);
l_help = cmdline.isSet(l_helpOption);
l_version = cmdline.isSet(l_versionOption);
l_verbose = cmdline.isSet(l_verboseOption);
l_debug = cmdline.isSet(l_debugOption);
} catch (ParseException exp) {
System.err.println("Bad Command Line. Reason: " + exp.getMessage());
getOptions().display();
System.exit(1);
}
return cmdline;
}
protected boolean isDebug(){
return l_debug;
}
protected boolean isVerbose(){
return l_verbose || l_debug;
}
public void run(String args[]) {
//:TODO:Hack
//DebugUtils.enableCommonsLogging();
//DebugUtils.enableHttpClientDebug();
UpdaterConfig.configure();
init();
CommandLine cmdline = parseCommandLine(args);
if (l_help) {
printHelp();
System.exit(0);
}
if (l_version) {
printVersion();
System.exit(0);
}
// Set logging context
int level = LogConstants.INFO;
if (l_verbose || l_debug)
level = l_debug ? LogConstants.DEBUG : LogConstants.VERBOSE;
if ( l_quiet )
level = LogConstants.ERROR;
if (!l_quiet )
printVersion();
Logger logger = Logger.pushContext(level, new StandardLogListener());
// Monitor (and store statistics)
l_statistics = new StatisticsMonitor();
Monitor monitor = Monitor.pushContext(l_statistics);
try {
execute(cmdline);
} catch (ParseException pe) {
SystemUtils.getSystemErr().println(
"Error: " + pe.getLocalizedMessage());
printHelp();
cmdline.print();
System.exit(1);
} catch (Exception exc) {
exc.printStackTrace();
} finally {
Monitor.popContext(monitor);
Logger.popContext(logger);
if (cmdline.isSet(l_statsOption)) {
DebugUtils.dump(l_statistics);
}
}
}
}
--- NEW FILE: ConfigTool.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krysalis.depot.update.tool;
import org.krysalis.depot.common.util.cli.CommandLine;
import org.krysalis.depot.common.util.cli.Option;
import org.krysalis.depot.update.config.UpdaterConfig;
import org.krysalis.depot.update.impl.ReferenceManager;
/**
*
* The Configuration Tool examines/queries configuration.
*
*/
public class ConfigTool extends Tool {
private static Option l_configOption = null;
static {
l_configOption = new Option("c", "config", true,
"The configuration file");
}
protected String getTitle() {
return "Configuration Tool";
}
protected void init() {
getOptions().addOption(l_configOption);
}
public void execute(CommandLine cmdline) throws Exception {
// Optional configuration
String configName = cmdline.getOptionValue(l_configOption);
if (null != configName)
UpdaterConfig.configure(configName);
else
UpdaterConfig.configure();
ReferenceManager.dump();
}
public static void main(String[] args) {
(new ConfigTool()).run(args);
}
}
--- NEW FILE: RepositoriesTool.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krysalis.depot.update.tool;
import org.krysalis.depot.common.util.cli.CommandLine;
import org.krysalis.depot.common.util.cli.Option;
import org.krysalis.depot.common.util.debug.DebugUtils;
import org.krysalis.depot.update.repository.RepositorySet;
import org.krysalis.depot.update.util.UpdateConstants;
/**
*/
public class RepositoriesTool extends Tool {
private static Option l_setOption = null;
private static Option l_groupsOption = null;
private static Option l_listOption = null;
static {
l_setOption = new Option("r", "repoSet", true, "RepositorySet");
l_groupsOption = new Option("g", "groups", false, "List groups");
l_listOption = new Option("l", "list", true, "List resources");
}
protected void init() {
getOptions().addOption(l_setOption);
getOptions().addOption(l_groupsOption);
getOptions().addOption(l_listOption);
}
protected String getTitle() {
return "Repositories Tool";
}
public void execute(CommandLine cmdline) throws Exception {
String setId =
cmdline.isSet(l_setOption)
? cmdline.getOptionValue(l_setOption)
: UpdateConstants.DEFAULT;
//DebugUtils.printSeparator();
//DebugUtils.dump(cmdline);
RepositorySet reposet = RepositorySet.getRepositorySet(setId, true);
DebugUtils.printSeparator();
DebugUtils.dump(reposet);
//:TODO:
// if (cmdline.isSet(l_groupsOption)) {
// DebugUtils.printSeparator();
// DebugUtils.dump(reposet.listGroups(AllSelector.getInstance()));
// }
//
// if (cmdline.isSet(l_listOption)) {
// DebugUtils.printSeparator();
// DebugUtils.dump(
// reposet.listResources(
// new ResourceGroup(
// cmdline.getMandatoryOptionValue(l_listOption)),
// AllSelector.getInstance()));
// }
}
public static void main(String[] args) {
(new RepositoriesTool()).run(args);
}
}
--- NEW FILE: ArtifactTool.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krysalis.depot.update.tool;
import org.krysalis.depot.common.util.cli.CommandLine;
import org.krysalis.depot.common.util.cli.Option;
import org.krysalis.depot.update.Artifact;
import org.krysalis.depot.update.ArtifactUpdater;
import org.krysalis.depot.update.ArtifactUpdaterFactory;
/**
*/
public class ArtifactTool extends Tool {
private static Option l_artifactOption = null;
static {
l_artifactOption =
new Option("a", "artifact", true, "The artifact to work on");
}
protected String getTitle() {
return "Artifact Tool";
}
protected void init() {
getOptions().addOption(l_artifactOption);
}
public void execute(CommandLine cmdline) throws Exception {
String artifact = cmdline.getMandatoryOptionValue(l_artifactOption);
ArtifactUpdater au = ArtifactUpdaterFactory.getDefaultUpdater();
au.getInstance(new Artifact(artifact));
}
public static void main(String[] args) {
(new ArtifactTool()).run(args);
}
}
--- NEW FILE: DownloaderTool.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krysalis.depot.update.tool;
import org.krysalis.depot.common.DepotException;
import org.krysalis.depot.common.log.Logger;
import org.krysalis.depot.common.util.cli.CommandLine;
import org.krysalis.depot.common.util.cli.Option;
import org.krysalis.depot.update.ArtifactUpdater;
import org.krysalis.depot.update.Repository;
import org.krysalis.depot.update.artifact.ArtifactGroup;
import org.krysalis.depot.update.config.UpdaterConfig;
import org.krysalis.depot.update.repository.DefaultRepository;
import org.krysalis.depot.update.repository.RepositorySet;
/**
*/
public class DownloaderTool extends Tool {
private static Option l_repoOption = null;
private static Option l_targetOption = null;
private static Option l_groupOption = null;
private static Option l_setOption = null;
private static Option l_configOption = null;
static {
l_repoOption = new Option("r", "repo", true, "Repository");
l_configOption = new Option("c", "config", true,
"The configuration file");
l_groupOption = new Option("g", "group", true, "The group to go get");
l_setOption = new Option("rs", "set", true, "The repository set to use");
l_targetOption = new Option("t", "target", true,
"The target directory to put it into");
}
protected String getTitle() {
return "Update Resource Tool";
}
protected void init() {
getOptions().addOption(l_repoOption);
getOptions().addOption(l_configOption);
getOptions().addOption(l_groupOption);
getOptions().addOption(l_setOption);
getOptions().addOption(l_targetOption);
}
private Repository getTargetRepository(String targetDir) {
return new DefaultRepository("target", targetDir);
}
public void execute(CommandLine cmdline) throws Exception {
// The group is the entity (a set of jars, e.g. junit)
String groupName = cmdline.getMandatoryOptionValue(l_groupOption);
// The name of the place (local repository)to put them
String targetDir = cmdline.getMandatoryOptionValue(l_targetOption);
// Optional configuration
String configName = cmdline.getOptionValue(l_configOption);
// Optional repository URL
String repoUrl = cmdline.getOptionValue(l_repoOption);
// Optional repository set name
String setName = cmdline.getOptionValue(l_setOption);
ArtifactUpdater updater = new ArtifactUpdater();
if (null != repoUrl) {
RepositorySet repoSet = new RepositorySet("gump");
repoSet.addRepository(new DefaultRepository("gump", repoUrl));
updater.setRepositorySet(repoSet);
Logger.getLogger().info("Repository @ " + repoUrl);
} else {
if (null != setName) {
updater.setRepositorySet(RepositorySet.getRepositorySet(setName,
false));
}
else
throw new DepotException("No repository URL or set specificed.");
}
if ( null != configName )
UpdaterConfig.configure(configName);
Logger.getLogger().info("Target Repository @ " + targetDir);
// Assigned the target (to copy into)
updater.setTargetRepository(getTargetRepository(targetDir));
// The group to go get
ArtifactGroup group = new ArtifactGroup(groupName);
Logger.getLogger().info("Artifact Group : " + groupName);
// Update...
updater.getArtifacts(group);
// Cleanup (to remove duplicates)
updater.cleanTarget(group);
}
public static void main(String[] args) {
(new DownloaderTool()).run(args);
}
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/