<plugin>\r
<groupId>org.apache.maven.plugins</groupId>\r
<artifactId>maven-dependency-plugin</artifactId>\r
+ <version>2.2</version>\r
<executions>\r
<execution>\r
<id>copy-dependencies</id>\r
</plugin>\r
\r
<plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
<artifactId>maven-release-plugin</artifactId>\r
+ <version>2.1</version>\r
<configuration>\r
- <tagBase>svn+ssh://tama3@svn.sourceforge.jp/svnroot/stigmata/tags</tagBase>\r
+ <tagBase>git:ssh://git@diamond.cse.kyoto-su.ac.jp:/stigmata/stigmata.git</tagBase>\r
</configuration>\r
</plugin>\r
</plugins>\r
* @author Haruaki Tamada
*/
public interface StigmataCommand{
+ public String getCommandString();
+
+ public String[] getMessages();
+
+ public int getMessageSize();
+
public boolean isAvailableArguments(String[] args);
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args);
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args);
- public void perform(Stigmata stigmata, String[] args);
+ public boolean perform(Stigmata stigmata, String[] args);
+
+ public void putMessage(String message);
public void setUp(BirthmarkEnvironment env);
public void tearDown(BirthmarkEnvironment env);
-
- public String getCommandString();
}
package jp.sourceforge.stigmata.command;
-import jp.sourceforge.stigmata.Stigmata;
+import java.util.ArrayList;
+import java.util.List;
+
import jp.sourceforge.stigmata.BirthmarkEnvironment;
+import jp.sourceforge.stigmata.Stigmata;
import jp.sourceforge.stigmata.StigmataCommand;
import jp.sourceforge.stigmata.hook.Phase;
import jp.sourceforge.stigmata.hook.StigmataHookManager;
* @author Haruaki Tamada
*/
public abstract class AbstractStigmataCommand implements StigmataCommand{
+ private List<String> messages = new ArrayList<String>();
+
+ @Override
+ public abstract String getCommandString();
+
+ @Override
+ public String[] getMessages(){
+ return messages.toArray(new String[messages.size()]);
+ }
+
+ @Override
+ public int getMessageSize(){
+ return messages.size();
+ }
+
+ @Override
+ public boolean isAvailableArguments(String[] args){
+ return true;
+ }
+
/**
* {@link perform(Stigmata, BirthmarkContext, String[]) <code>perform(stigmata, stigmata.createContext(), args)</code>}.
*/
@Override
- public void perform(Stigmata stigmata, String[] args){
- perform(stigmata, stigmata.createContext(), args);
+ public boolean perform(Stigmata stigmata, String[] args){
+ return perform(stigmata, stigmata.createContext(), args);
}
@Override
- public boolean isAvailableArguments(String[] args){
- return true;
+ public void putMessage(String message){
+ messages.add(message);
}
@Override
public void tearDown(BirthmarkEnvironment env){
StigmataHookManager.getInstance().runHook(Phase.TEAR_DOWN, env);
}
-
- @Override
- public abstract String getCommandString();
}
}
@Override
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
try{
BirthmarkEngine engine = new BirthmarkEngine(context.getEnvironment());
context.setComparisonMethod(ComparisonMethod.ROUND_ROBIN_SAME_PAIR);
}catch(Exception e){
e.printStackTrace();
}
+ return true;
}
}
}
@Override
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ PrintWriter out = null;
try{
- PrintWriter out;
if(args == null || args.length == 0){
out = new PrintWriter(System.out);
}
}
new ConfigFileExporter(context.getEnvironment()).export(out);
- out.close();
+ return true;
}catch(IOException e){
+ return false;
+ } finally{
+ if(out != null){
+ out.close();
+ }
}
}
}
}
@Override
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
try{
context.setComparisonMethod(ComparisonMethod.ROUND_ROBIN_SAME_PAIR);
BirthmarkEngine engine = new BirthmarkEngine(context.getEnvironment());
}catch(Exception ex){
ex.printStackTrace();
}
+ return true;
}
}
*/
public class GuiCommand extends AbstractStigmataCommand{
@Override
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
StigmataFrame frame = new StigmataFrame(stigmata, context.getEnvironment());
frame.setVisible(true);
+ return true;
}
@Override
}
@Override
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
BirthmarkEnvironment env = context.getEnvironment();
Package p = getClass().getPackage();
System.out.println();
System.out.println(helpResource.getString("cli.interface.copyright"));
System.out.println(helpResource.getString("cli.interface.mailto"));
+
+ return true;
}
}
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
import jp.sourceforge.stigmata.BirthmarkContext;
import jp.sourceforge.stigmata.BirthmarkEnvironment;
}
@Override
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
File pluginsDir = new File(BirthmarkEnvironment.getStigmataHome(), "plugins");
BirthmarkEnvironment env = context.getEnvironment();
+ List<String> messages = new ArrayList<String>();
for(int i = 0; i < args.length; i++){
File pluginSource = new File(args[i]);
File pluginDest = new File(pluginsDir, pluginSource.getName());
- if(!Utility.isStigmataPluginJarFile(pluginSource)){
+ if(!Utility.isStigmataPluginJarFile(pluginSource, messages)){
+ for(String msg: messages){
+ putMessage(msg);
+ }
throw new IllegalArgumentException(pluginSource + ": not stigmata plugin file.");
}
if(pluginDest.exists()){
pluginDest.renameTo(backupFile);
}
}
+ copyFile(pluginSource, pluginDest);
+ File parent = pluginSource.getParentFile();
+ File destParent = pluginDest.getParentFile();
+ String[] myDependencies = null;
+ for(String dependency: Utility.getDependencies(pluginSource)){
+ if(myDependencies == null){
+ myDependencies = findStigmataDependencies();
+ }
+ boolean include = false;
+ for(String systemDependency: myDependencies){
+ if(dependency.equals(systemDependency)){
+ include = true;
+ break;
+ }
+ }
+ if(!include){
+ File dependencyFile = new File(parent, dependency);
+ if(dependencyFile.exists()){
+ copyFile(dependencyFile, new File(destParent, dependency));
+ }
+ else{
+ putMessage(dependency + ": not found. Install this jar file into plugin directory");
+ }
+ }
+ }
+ }
+ return getMessageSize() == 0;
+ }
- byte[] data = new byte[256];
- int read;
-
+ private String[] findStigmataDependencies(){
+ URL url = getClass().getResource("/jp/sourceforge/stigmata/command/InstallCommand.class");
+ String jarfilePath = url.toString();
+ String[] deps = new String[0];
+ if(jarfilePath.startsWith("jar:")){
+ jarfilePath = jarfilePath.substring("jar:".length(), jarfilePath.lastIndexOf("!"));
try{
- InputStream in = new FileInputStream(pluginSource);
- OutputStream out = new FileOutputStream(pluginDest);
+ deps = Utility.getDependencies(new File(new URI(jarfilePath)));
+ } catch(URISyntaxException e){
+ e.printStackTrace();
+ }
+ }
+ return deps;
+ }
- while((read = in.read(data)) != -1){
- out.write(data, 0, read);
- }
- in.close();
- out.close();
- } catch(IOException e){
+ private void copyFile(File source, File dest){
+ byte[] data = new byte[256];
+ int read;
+
+ try{
+ InputStream in = new FileInputStream(source);
+ OutputStream out = new FileOutputStream(dest);
+
+ while((read = in.read(data)) != -1){
+ out.write(data, 0, read);
}
+ in.close();
+ out.close();
+ } catch(IOException e){
}
}
}
}
@Override
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ BufferedReader reader = null;
try{
InputStream in = getClass().getResourceAsStream("/META-INF/license.txt");
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ reader = new BufferedReader(new InputStreamReader(in));
String line;
while((line = reader.readLine()) != null){
System.out.println(line);
}
reader.close();
+ return true;
}catch(IOException ex){
- ex.printStackTrace();
+ return false;
+ } finally{
+ if(reader != null){
+ try{
+ reader.close();
+ } catch(IOException e){
+ }
+ }
}
}
}
}
@Override
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
BirthmarkService[] spis = context.getEnvironment().findServices();
ResultPrinterService spi = stigmata.getPrinterManager().getService(context.getFormat());
BirthmarkServicePrinter formatter = spi.getBirthmarkServicePrinter();
}catch(IOException e){
e.printStackTrace();
}
+ return true;
}
private String validateTarget(String fileName, String format){
}
@Override
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
File pluginsDir = new File(BirthmarkEnvironment.getStigmataHome(), "plugins");
BirthmarkEnvironment env = context.getEnvironment();
boolean removeServiceInConfigFile = false;
if(removeServiceInConfigFile){
updateConfigFile(env);
}
+ return true;
}
private void updateConfigFile(BirthmarkEnvironment env){
}
@Override
- public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
+ public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
ResourceBundle helpResource = ResourceBundle.getBundle("resources.options");
Package p = getClass().getPackage();
System.out.printf("%s %s%n", helpResource.getString("cli.version.header"), p.getImplementationVersion());
+ return true;
}
}
new String[] { "jar", },
messages.get("installplugin.fileopen.description")
);
- List<String> messages = new ArrayList<String>();
if(pluginFile == null){
return;
}
- if(Utility.isStigmataPluginJarFile(pluginFile, messages)){
- StigmataCommand command = StigmataCommandFactory.getInstance().getCommand("install");
- String path = pluginFile.getPath();
- command.perform(getStigmata(), new String[] { path });
+ StigmataCommand command = StigmataCommandFactory.getInstance().getCommand("install");
+ String path = pluginFile.getPath();
+ boolean installFlag = command.perform(getStigmata(), new String[] { path });
+ if(installFlag){
int flag = JOptionPane.showConfirmDialog(
this, getMessages().get("reload.after.installplugin"),
getMessages().get("reload.after.installplugin.title"),
StringBuilder sb = new StringBuilder("<html><body>");
sb.append("<p>").append(getMessages().format("install.error", pluginFile.getPath())).append("</p>");
sb.append("<ul>");
- for(String message: messages){
- sb.append("<li>").append(getMessages().get(message)).append("</li>");
+ for(String message: command.getMessages()){
+ sb.append("<li>").append(message).append("</li>");
}
sb.append("</ul></body></html>");
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+import java.util.jar.Manifest;
public class Utility{
/**
return new String(builder);
}
- public static boolean isStigmataPluginJarFile(File pluginFile){
- return isStigmataPluginJarFile(pluginFile, new ArrayList<String>());
+ public static String[] getDependencies(File source){
+ JarFile jarfile = null;
+ try{
+ jarfile = new JarFile(source);
+ Manifest manifest = jarfile.getManifest();
+ String classPath = manifest.getMainAttributes().getValue("Class-Path");
+ if(classPath != null && !classPath.equals("")){
+ return classPath.split("[ \t]");
+ }
+ } catch(IOException e){
+ } finally{
+ if(jarfile != null){
+ try{
+ jarfile.close();
+ } catch(IOException e){
+ }
+ }
+ }
+ return new String[0];
}
public static boolean isStigmataPluginJarFile(File pluginFile, List<String> messages){