summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-11-13 01:40:16 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-11-13 01:40:16 +0000
commitad165acb2adc3028c78618e607906bed5d26942d (patch)
treeaef75c1e6b3c808fda2bbea3a71637293b32f752
parente192cc63f4468e3be3f46b87fa7e5adaa09702f6 (diff)
Resolve bundles after the compilation is done.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@713611 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/JavaCompiler.java70
-rw-r--r--branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/osgi/BundleUtil.java7
2 files changed, 44 insertions, 33 deletions
diff --git a/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/JavaCompiler.java b/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/JavaCompiler.java
index 956817ff47..eb33804862 100644
--- a/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/JavaCompiler.java
+++ b/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/JavaCompiler.java
@@ -33,6 +33,7 @@ import static org.eclipse.jdt.internal.compiler.impl.CompilerOptions.OPTION_Targ
import static org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WARNING;
import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -44,6 +45,7 @@ import java.util.Map;
import java.util.Set;
import org.apache.tuscany.sca.tools.maven.compiler.osgi.BundleResolver;
+import org.apache.tuscany.sca.tools.maven.compiler.osgi.BundleUtil;
import org.codehaus.plexus.compiler.AbstractCompiler;
import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.compiler.CompilerError;
@@ -73,46 +75,15 @@ public class JavaCompiler extends AbstractCompiler {
getLogger().info("Invoking Tuscany Eclipse JDT compiler");
- // getLogger().info(configuration.getCustomCompilerArguments().toString());
- boolean osgi = "true".equals(configuration.getCustomCompilerArguments().get("-osgi"));
- if (osgi) {
- getLogger().info("Enforcing OSGi bundle resolution");
- }
List<URL> urls = new ArrayList<URL>();
try {
- // urls.add(new File(configuration.getOutputLocation()).toURI().toURL());
for (String entry : (List<String>)configuration.getClasspathEntries()) {
- if (osgi) {
- try {
- File cp = new File(entry);
- if (cp.exists()) {
- stateController.addBundle(cp);
- }
- } catch (BundleException e) {
- getLogger().error(e.getMessage(), e);
- }
- }
urls.add(new File(entry).toURI().toURL());
}
} catch (MalformedURLException e) {
throw new CompilerException(e.getMessage(), e);
}
- if (osgi) {
- stateController.resolveState();
- for (BundleDescription b : stateController.getBundles()) {
- if (b != null) {
- try {
- stateController.assertResolved(b);
- } catch (BundleException e) {
- getLogger().error(stateController.getAllErrors().toString());
- // FIXME: For now, only a warning is reported
- // throw new CompilerException(e.getMessage(), e);
- }
- }
- }
- }
-
ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
// Determine compiler configuration
@@ -188,6 +159,43 @@ public class JavaCompiler extends AbstractCompiler {
getLogger().info("Compiling " + compilationUnits.size() + " to " + configuration.getOutputLocation());
compiler.compile((ICompilationUnit[])compilationUnits.toArray(new ICompilationUnit[compilationUnits.size()]));
+ // getLogger().info(configuration.getCustomCompilerArguments().toString());
+ boolean osgi = "true".equals(configuration.getCustomCompilerArguments().get("-osgi"));
+ File proj = new File(configuration.getOutputLocation());
+ String symbol = null;
+ try {
+ symbol = BundleUtil.getBundleSymbolicName(proj);
+ } catch (IOException e1) {
+ symbol = null;
+ }
+
+ if (osgi && symbol != null) {
+ getLogger().info("Resolving OSGi bundles");
+ for (String entry : (List<String>)configuration.getClasspathEntries()) {
+ try {
+ File cp = new File(entry);
+ if (cp.exists()) {
+ stateController.addBundle(cp);
+ }
+ } catch (BundleException e) {
+ getLogger().error(e.getMessage(), e);
+ }
+ }
+
+ stateController.resolveState();
+ BundleDescription b = stateController.getBundleDescription(proj);
+ if (b != null) {
+ try {
+ stateController.assertResolved(b);
+ getLogger().info("OSGi bundle is resolved: " + b.getSymbolicName());
+ } catch (BundleException e) {
+ getLogger().error(stateController.getAllErrors().toString());
+ // FIXME: For now, only a warning is reported
+ // throw new CompilerException(e.getMessage(), e);
+ }
+ }
+ }
+
return compilerErrors;
}
diff --git a/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/osgi/BundleUtil.java b/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/osgi/BundleUtil.java
index 0869183686..9e99fe4790 100644
--- a/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/osgi/BundleUtil.java
+++ b/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/osgi/BundleUtil.java
@@ -59,7 +59,7 @@ import org.osgi.framework.Version;
*
* @version $Rev$ $Date$
*/
-final class BundleUtil {
+public final class BundleUtil {
/**
* Returns the name of a bundle, or null if the given file is not a bundle.
@@ -68,13 +68,16 @@ final class BundleUtil {
* @return
* @throws IOException
*/
- static String getBundleSymbolicName(File file) throws IOException {
+ public static String getBundleSymbolicName(File file) throws IOException {
if (!file.exists()) {
return null;
}
String bundleName = null;
if (file.isDirectory()) {
File mf = new File(file, JarFile.MANIFEST_NAME);
+ if (!mf.isFile()) {
+ mf = new File(file, "../../" + JarFile.MANIFEST_NAME);
+ }
if (mf.isFile()) {
Manifest manifest = new Manifest(new FileInputStream(mf));
bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);