You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by fe...@apache.org on 2007/12/09 18:05:17 UTC

svn commit: r602697 - /directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java

Author: felixk
Date: Sun Dec  9 09:05:15 2007
New Revision: 602697

URL: http://svn.apache.org/viewvc?rev=602697&view=rev
Log:
Some changes to fix classpath.

Modified:
    directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java

Modified: directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java?rev=602697&r1=602696&r2=602697&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java (original)
+++ directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java Sun Dec  9 09:05:15 2007
@@ -114,7 +114,8 @@
      */
     private List<Artifact> createArtifactList() {
         List<Artifact> list = new ArrayList<Artifact>();
-        for (Iterator<Artifact> artifactItem = project.getArtifacts().iterator(); artifactItem.hasNext();) {
+        for (Iterator<Artifact> artifactItem = project.getArtifacts()
+                .iterator(); artifactItem.hasNext();) {
             Artifact artifact = (Artifact) artifactItem.next();
             if (!artifact.getScope().equalsIgnoreCase("provided")) {
                 list.add(artifact);
@@ -138,9 +139,11 @@
                 copyDir.mkdirs();
 
             for (Artifact artifact : list) {
-                final File destFile = new File(copyDir, artifact.getFile().getName());
+                final File destFile = new File(copyDir, artifact.getFile()
+                        .getName());
                 FileUtils.copyFile(artifact.getFile(), destFile);
-                getLog().info("Copying " + artifact.getFile() + " to " + destFile);
+                getLog().info(
+                        "Copying " + artifact.getFile() + " to " + destFile);
             }
         }
     }
@@ -152,14 +155,17 @@
      * @throws FileNotFoundException
      * @throws IOException
      */
-    private void updateManifest(final List<Artifact> list) throws FileNotFoundException, IOException {
-        final File manifestFile = new File(project.getBasedir(), "META-INF/MANIFEST.MF");
+    private void updateManifest(final List<Artifact> list)
+            throws FileNotFoundException, IOException {
+        final File manifestFile = new File(project.getBasedir(),
+                "META-INF/MANIFEST.MF");
         getLog().info("Update Bundle-Classpath in " + manifestFile);
 
         // Build Bundle-ClassPath entry
         final StringBuilder bundleClasspath = new StringBuilder(" .");
         for (Artifact artifact : list) {
-            bundleClasspath.append(",").append(NEWLINE).append(" ").append(libraryPath).append(File.separator).append(
+            bundleClasspath.append(",").append(NEWLINE).append(" ").append(
+                    libraryPath).append(File.separator).append(
                     artifact.getFile().getName());
         }
 
@@ -168,7 +174,8 @@
         // Read existing MANIFEST.MF and add existing entries
         // to StringBuilder exept Bundle-ClassPath entry
         StringBuilder manifestSb = new StringBuilder();
-        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(manifestFile), "UTF-8"));
+        BufferedReader in = new BufferedReader(new InputStreamReader(
+                new FileInputStream(manifestFile), "UTF-8"));
         String line;
         while ((line = in.readLine()) != null) {
             if (inBundleClasspathEntry && line.indexOf(":") > -1) {
@@ -187,10 +194,12 @@
         }
 
         // Add Bundle-ClassPath entry
-        manifestSb.append(ENTRY_BUNDLE_CLASSPATH).append(bundleClasspath).append(NEWLINE);
+        manifestSb.append(ENTRY_BUNDLE_CLASSPATH).append(bundleClasspath)
+                .append(NEWLINE);
 
         // Write MANIFEST.MF
-        Writer out = new OutputStreamWriter(new FileOutputStream(manifestFile), "UTF-8");
+        Writer out = new OutputStreamWriter(new FileOutputStream(manifestFile),
+                "UTF-8");
         out.write(manifestSb.toString());
         out.flush();
         out.close();
@@ -201,26 +210,36 @@
      * 
      * @param list
      */
-    private void updateDotClasspath(final List<Artifact> list) throws IOException, XmlPullParserException {
+    private void updateDotClasspath(List<Artifact> list) throws IOException,
+            XmlPullParserException {
         getLog().info("Update .classpath in " + project.getBasedir());
-        InputStream is = new FileInputStream(new File(project.getBasedir(), ".classpath"));
+        final InputStream is = new FileInputStream(new File(project
+                .getBasedir(), ".classpath"));
         Xpp3Dom dom = Xpp3DomBuilder.build(is, "UTF-8");
+        int cnt = 0;
         for (Xpp3Dom cpEntry : dom.getChildren("classpathentry")) {
-            final String pathValue = cpEntry.getAttribute("path");
-            for (Artifact artifact : list) {
-                if (pathValue.indexOf(artifact.getFile().getName()) > -1) {
-                    cpEntry.setAttribute("exported", "true");
-                    cpEntry.setAttribute("kind", "lib");
-                    cpEntry.setAttribute("path", libraryPath + File.separator + artifact.getFile().getName());
-                }
+            if (cpEntry.getAttribute("kind").equals("lib")) {
+                dom.removeChild(cnt);
+                cnt--;
             }
+            cnt++;
         }
-        is.close();
-        Writer w;
 
-        w = new OutputStreamWriter(new FileOutputStream(new File(project.getBasedir(), ".classpath")), "UTF-8");
+        for (Artifact artifact : list) {
+            final Xpp3Dom entry = new Xpp3Dom("classpathentry");
+            entry.setAttribute("exported", "true");
+            entry.setAttribute("kind", "lib");
+            entry.setAttribute("path", (new StringBuilder())
+                    .append(libraryPath).append(File.separator).append(
+                            artifact.getFile().getName()).toString());
+            dom.addChild(entry);
+        }
 
-        XMLWriter writer = new PrettyPrintXMLWriter(w);
+        is.close();
+        Writer w = new OutputStreamWriter(new FileOutputStream(new File(project
+                .getBasedir(), ".classpath")), "UTF-8");
+        org.codehaus.plexus.util.xml.XMLWriter writer = new PrettyPrintXMLWriter(
+                w);
         Xpp3DomWriter.write(writer, dom);
         w.flush();
         w.close();
@@ -232,12 +251,15 @@
      * @param list
      */
     private void updateDotProject() throws IOException, XmlPullParserException {
-        getLog().info((new StringBuilder()).append("Update .project in ").append(project.getBasedir()).toString());
-        InputStream is = new FileInputStream(new File(project.getBasedir(), ".project"));
+        getLog().info("Update .project in " + project.getBasedir());
+        InputStream is = new FileInputStream(new File(project.getBasedir(),
+                ".project"));
         Xpp3Dom dom = Xpp3DomBuilder.build(is, "UTF-8");
         int cnt = 0;
-        for (Xpp3Dom cpEntry : dom.getChild("buildSpec").getChildren("buildCommand")) {
-            if (cpEntry.getChild("name").getValue().equals("org.eclipse.ui.externaltools.ExternalToolBuilder")) {
+        for (Xpp3Dom cpEntry : dom.getChild("buildSpec").getChildren(
+                "buildCommand")) {
+            if (cpEntry.getChild("name").getValue().equals(
+                    "org.eclipse.ui.externaltools.ExternalToolBuilder")) {
                 dom.getChild("buildSpec").removeChild(cnt);
                 cnt--;
             }
@@ -248,8 +270,10 @@
         removeChildFromDom(dom, "projects");
 
         is.close();
-        Writer w = new OutputStreamWriter(new FileOutputStream(new File(project.getBasedir(), ".project")), "UTF-8");
-        org.codehaus.plexus.util.xml.XMLWriter writer = new PrettyPrintXMLWriter(w);
+        Writer w = new OutputStreamWriter(new FileOutputStream(new File(project
+                .getBasedir(), ".project")), "UTF-8");
+        org.codehaus.plexus.util.xml.XMLWriter writer = new PrettyPrintXMLWriter(
+                w);
         Xpp3DomWriter.write(writer, dom);
         w.flush();
         w.close();