diff options
Diffstat (limited to 'org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExternalRuntime.java')
-rw-r--r-- | org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExternalRuntime.java | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExternalRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExternalRuntime.java index 0c91e580..3603d7fb 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExternalRuntime.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExternalRuntime.java @@ -35,12 +35,12 @@ import org.eclipse.m2e.core.embedder.MavenRuntime; import org.eclipse.m2e.core.internal.IMavenConstants; import org.eclipse.m2e.core.internal.Messages; + /** * Maven external runtime using ClassWorlds launcher * * @author Eugene Kuleshov * @author Igor Fedorenko - * */ public class MavenExternalRuntime implements MavenRuntime { private static final Logger log = LoggerFactory.getLogger(MavenExternalRuntime.class); @@ -48,12 +48,11 @@ public class MavenExternalRuntime implements MavenRuntime { private static final String PROPERTY_MAVEN_HOME = "maven.home"; //$NON-NLS-1$ private final String location; - public MavenExternalRuntime(String location) { this.location = location; } - + public boolean isEditable() { return true; } @@ -61,15 +60,15 @@ public class MavenExternalRuntime implements MavenRuntime { public boolean isAvailable() { return new File(location, "bin").exists() && getLauncherClasspath() != null; //$NON-NLS-1$ } - + public String getLocation() { return location; } - + public String getSettings() { return location + File.separator + "conf" + File.separator + "settings.xml"; //$NON-NLS-1$ //$NON-NLS-2$ } - + public String getMainTypeName() { return "org.codehaus.classworlds.Launcher"; //$NON-NLS-1$ } @@ -78,8 +77,9 @@ public class MavenExternalRuntime implements MavenRuntime { return new File(location, "bin/m2.conf"); //$NON-NLS-1$ } - public void createLauncherConfiguration(final IMavenLauncherConfiguration collector, IProgressMonitor monitor) throws CoreException { - + public void createLauncherConfiguration(final IMavenLauncherConfiguration collector, IProgressMonitor monitor) + throws CoreException { + collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM); collector.addArchiveEntry(getLauncherClasspath()); @@ -87,6 +87,7 @@ public class MavenExternalRuntime implements MavenRuntime { public void addImportFrom(String relamName, String importSpec) { throw new UnsupportedOperationException(Messages.MavenExternalRuntime_exc_unsupported); } + public void addLoadFile(File file) { try { collector.addArchiveEntry(file.getAbsolutePath()); @@ -94,6 +95,7 @@ public class MavenExternalRuntime implements MavenRuntime { throw new ExceptionWrapper(ex); } } + public void addLoadURL(URL url) { try { collector.addArchiveEntry(url.toExternalForm()); @@ -101,9 +103,11 @@ public class MavenExternalRuntime implements MavenRuntime { throw new ExceptionWrapper(ex); } } + public void addRealm(String realmName) { collector.addRealm(realmName); } + public void setAppMain(String mainClassName, String mainRealmName) { collector.setMainType(mainClassName, mainRealmName); } @@ -113,7 +117,7 @@ public class MavenExternalRuntime implements MavenRuntime { properties.put(PROPERTY_MAVEN_HOME, location); ConfigurationParser parser = new ConfigurationParser(handler, properties); - + try { FileInputStream is = new FileInputStream(getLauncherConfigurationFile()); try { @@ -121,11 +125,12 @@ public class MavenExternalRuntime implements MavenRuntime { } finally { is.close(); } - } catch (Exception e) { - if (e instanceof ExceptionWrapper && e.getCause() instanceof CoreException) { + } catch(Exception e) { + if(e instanceof ExceptionWrapper && e.getCause() instanceof CoreException) { throw (CoreException) e.getCause(); } - throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, Messages.MavenExternalRuntime_error_cannot_parse, e)); + throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, + Messages.MavenExternalRuntime_error_cannot_parse, e)); } // XXX show error dialog and fail launch @@ -137,7 +142,7 @@ public class MavenExternalRuntime implements MavenRuntime { } return false; } - + public int hashCode() { return location.hashCode(); } @@ -148,6 +153,7 @@ public class MavenExternalRuntime implements MavenRuntime { private static class ExceptionWrapper extends RuntimeException { private static final long serialVersionUID = 8815818826909815028L; + public ExceptionWrapper(Exception cause) { super(cause); } @@ -157,15 +163,14 @@ public class MavenExternalRuntime implements MavenRuntime { File mavenHome = new File(location); DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(mavenHome); - ds.setIncludes(new String[] { - "core/boot/classworlds*.jar", // 2.0.4 //$NON-NLS-1$ + ds.setIncludes(new String[] {"core/boot/classworlds*.jar", // 2.0.4 //$NON-NLS-1$ "boot/classworlds*.jar", // 2.0.7 //$NON-NLS-1$ "boot/plexus-classworlds*.jar", // 2.1 as of 2008-03-27 //$NON-NLS-1$ }); ds.scan(); String[] includedFiles = ds.getIncludedFiles(); - if (includedFiles.length == 1) { + if(includedFiles.length == 1) { return new File(mavenHome, includedFiles[0]).getAbsolutePath(); } @@ -173,26 +178,33 @@ public class MavenExternalRuntime implements MavenRuntime { } public String getVersion() { - + class VersionHandler implements ConfigurationHandler { File mavenCore; + File uber; + public void addImportFrom(String relamName, String importSpec) { } + public void addLoadFile(File file) { - if (file.getName().contains("maven-core")) { //$NON-NLS-1$ + if(file.getName().contains("maven-core")) { //$NON-NLS-1$ mavenCore = file; - } else if (file.getName().endsWith("uber.jar")) { //$NON-NLS-1$ + } else if(file.getName().endsWith("uber.jar")) { //$NON-NLS-1$ uber = file; } } + public void addLoadURL(URL url) { } + public void addRealm(String realmName) { } + public void setAppMain(String mainClassName, String mainRealmName) { } - }; + } + ; VersionHandler handler = new VersionHandler(); Properties properties = new Properties(); @@ -209,20 +221,20 @@ public class MavenExternalRuntime implements MavenRuntime { } ZipFile zip = null; - if (handler.mavenCore != null) { + if(handler.mavenCore != null) { zip = new ZipFile(handler.mavenCore); - } else if (handler.uber != null) { + } else if(handler.uber != null) { zip = new ZipFile(handler.uber); } - if (zip != null) { + if(zip != null) { try { ZipEntry zipEntry = zip.getEntry("META-INF/maven/org.apache.maven/maven-core/pom.properties"); //$NON-NLS-1$ - if (zipEntry != null) { + if(zipEntry != null) { Properties pomProperties = new Properties(); pomProperties.load(zip.getInputStream(zipEntry)); - + String version = pomProperties.getProperty("version"); //$NON-NLS-1$ - if (version != null) { + if(version != null) { return version; } } @@ -230,11 +242,11 @@ public class MavenExternalRuntime implements MavenRuntime { zip.close(); } } - } catch (Exception e) { + } catch(Exception e) { // most likely a bad location, but who knows log.error("Could not parse classwords configuration file", e); } return Messages.MavenExternalRuntime_unknown; } -}
\ No newline at end of file +} |