Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 222585 Details for
Bug 269201
[jar exporter] ant file produced by Export runnable jar contains absolute paths instead of relative to workspace
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Alternative Patch
patch.diff (text/plain), 17.65 KB, created by
Matthias Reinhardt
on 2012-10-19 11:36:27 EDT
(
hide
)
Description:
Alternative Patch
Filename:
MIME Type:
Creator:
Matthias Reinhardt
Created:
2012-10-19 11:36:27 EDT
Size:
17.65 KB
patch
obsolete
>+++ org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarAntExporter.java Fri Oct 19 14:25:11 2012 >@@ -14,6 +14,7 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.jarpackagerfat; > >+import java.io.File; > import java.io.FileNotFoundException; > import java.io.IOException; > import java.util.ArrayList; >@@ -162,6 +163,13 @@ > } > > return result; >+ } >+ >+ protected File GetRelativePath(File actualDir, File baseDir) { >+ java.nio.file.Path basePath= baseDir.toPath(); >+ java.nio.file.Path path= actualDir.toPath(); >+ >+ return basePath.relativize(path).toFile(); > } > > /** >+++ org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarRsrcUrlAntExporter.java Fri Oct 19 14:18:30 2012 >@@ -56,7 +56,7 @@ > @Override > protected void buildANTScript(IPath antScriptLocation, String projectName, IPath absJarfile, String mainClass, SourceInfo[] sourceInfos) throws FileNotFoundException, IOException { > File antScriptFile= antScriptLocation.toFile(); >- buildANTScript(new FileOutputStream(antScriptFile), projectName, absJarfile, mainClass, sourceInfos); >+ buildANTScript(antScriptFile, projectName, absJarfile, mainClass, sourceInfos); > copyJarInJarLoader(new File(antScriptFile.getParentFile(), FatJarRsrcUrlBuilder.JAR_RSRC_LOADER_ZIP)); > } > >@@ -74,103 +74,116 @@ > is.close(); > } > >- protected void buildANTScript(OutputStream outputStream, String projectName, IPath absJarfile, String mainClass, SourceInfo[] sourceInfos) throws IOException { >- >- String absJarname= absJarfile.toString(); >- >- DocumentBuilder docBuilder= null; >- DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); >- factory.setValidating(false); >+ protected void buildANTScript(File antScriptFile, String projectName, IPath jarFileLocation, String mainClass, SourceInfo[] sourceInfos) throws IOException { >+ OutputStream outputStream= null; >+ > try { >- docBuilder= factory.newDocumentBuilder(); >- } catch (ParserConfigurationException ex) { >- throw new IOException(FatJarPackagerMessages.FatJarPackageAntScript_error_couldNotGetXmlBuilder); >- } >- Document document= docBuilder.newDocument(); >- >- Node comment; >- >- // Create the document >- Element project= document.createElement("project"); //$NON-NLS-1$ >- project.setAttribute("name", "Create Runnable Jar for Project " + projectName + " with Jar-in-Jar Loader"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >- project.setAttribute("default", "create_run_jar"); //$NON-NLS-1$ //$NON-NLS-2$ >- comment= document.createComment("this file was created by Eclipse Runnable JAR Export Wizard"); //$NON-NLS-1$ >- project.appendChild(comment); >- comment= document.createComment("ANT 1.7 is required "); //$NON-NLS-1$ >- project.appendChild(comment); >- document.appendChild(project); >- >- Element target= document.createElement("target"); //$NON-NLS-1$ >- target.setAttribute("name", "create_run_jar"); //$NON-NLS-1$ //$NON-NLS-2$ >- project.appendChild(target); >- >- Element jar= document.createElement("jar"); //$NON-NLS-1$ >- jar.setAttribute("destfile", absJarname); //$NON-NLS-1$s >- target.appendChild(jar); >- >- Element manifest= document.createElement("manifest"); //$NON-NLS-1$ >- jar.appendChild(manifest); >- >- Element attribute= document.createElement("attribute"); //$NON-NLS-1$ >- attribute.setAttribute("name", "Main-Class"); //$NON-NLS-1$ //$NON-NLS-2$s >- attribute.setAttribute("value", JIJConstants.LOADER_MAIN_CLASS); //$NON-NLS-1$ >- manifest.appendChild(attribute); >- >- attribute= document.createElement("attribute"); //$NON-NLS-1$ >- attribute.setAttribute("name", JIJConstants.REDIRECTED_MAIN_CLASS_MANIFEST_NAME); //$NON-NLS-1$ >- attribute.setAttribute("value", mainClass); //$NON-NLS-1$ >- manifest.appendChild(attribute); >- >- attribute= document.createElement("attribute"); //$NON-NLS-1$ >- attribute.setAttribute("name", "Class-Path"); //$NON-NLS-1$ //$NON-NLS-2$s >- attribute.setAttribute("value", "."); //$NON-NLS-1$ //$NON-NLS-2$ >- manifest.appendChild(attribute); >- >- attribute= document.createElement("attribute"); //$NON-NLS-1$ >- attribute.setAttribute("name", JIJConstants.REDIRECTED_CLASS_PATH_MANIFEST_NAME); //$NON-NLS-1$ >- StringBuffer rsrcClassPath= new StringBuffer(); >- rsrcClassPath.append(JIJConstants.CURRENT_DIR); >- for (int i= 0; i < sourceInfos.length; i++) { >- SourceInfo sourceInfo= sourceInfos[i]; >- if (sourceInfo.isJar) { >- rsrcClassPath.append(" ") //$NON-NLS-1$ >- .append(new File(sourceInfo.absPath).getName()); >+ outputStream= new FileOutputStream(antScriptFile); >+ File antScriptFolder= antScriptFile.getParentFile(); >+ >+ File jarFile= GetRelativePath(jarFileLocation.toFile(), antScriptFolder); >+ >+ DocumentBuilder docBuilder= null; >+ DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); >+ factory.setValidating(false); >+ try { >+ docBuilder= factory.newDocumentBuilder(); >+ } catch (ParserConfigurationException ex) { >+ throw new IOException(FatJarPackagerMessages.FatJarPackageAntScript_error_couldNotGetXmlBuilder); > } >- } >- attribute.setAttribute("value", rsrcClassPath.toString()); //$NON-NLS-1$ >- manifest.appendChild(attribute); >- >- Element zipfileset= document.createElement("zipfileset"); //$NON-NLS-1$ >- zipfileset.setAttribute("src", FatJarRsrcUrlBuilder.JAR_RSRC_LOADER_ZIP); //$NON-NLS-1$ >- jar.appendChild(zipfileset); >- >- for (int i= 0; i < sourceInfos.length; i++) { >- SourceInfo sourceInfo= sourceInfos[i]; >- if (sourceInfo.isJar) { >- File jarFile= new File(sourceInfo.absPath); >- Element fileset= document.createElement("zipfileset"); //$NON-NLS-1$ >- fileset.setAttribute("dir", jarFile.getParent()); //$NON-NLS-1$ >- fileset.setAttribute("includes", jarFile.getName()); //$NON-NLS-1$ >- jar.appendChild(fileset); >- } else { >- Element fileset= document.createElement("fileset"); //$NON-NLS-1$ >- fileset.setAttribute("dir", sourceInfo.absPath); //$NON-NLS-1$ >- jar.appendChild(fileset); >+ Document document= docBuilder.newDocument(); >+ >+ Node comment; >+ >+ // Create the document >+ Element project= document.createElement("project"); //$NON-NLS-1$ >+ project.setAttribute("name", "Create Runnable Jar for Project " + projectName + " with Jar-in-Jar Loader"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ project.setAttribute("default", "create_run_jar"); //$NON-NLS-1$ //$NON-NLS-2$ >+ comment= document.createComment("this file was created by Eclipse Runnable JAR Export Wizard"); //$NON-NLS-1$ >+ project.appendChild(comment); >+ comment= document.createComment("ANT 1.7 is required "); //$NON-NLS-1$ >+ project.appendChild(comment); >+ document.appendChild(project); >+ >+ Element target= document.createElement("target"); //$NON-NLS-1$ >+ target.setAttribute("name", "create_run_jar"); //$NON-NLS-1$ //$NON-NLS-2$ >+ project.appendChild(target); >+ >+ Element jar= document.createElement("jar"); //$NON-NLS-1$ >+ jar.setAttribute("destfile", jarFile.toString()); //$NON-NLS-1$s >+ target.appendChild(jar); >+ >+ Element manifest= document.createElement("manifest"); //$NON-NLS-1$ >+ jar.appendChild(manifest); >+ >+ Element attribute= document.createElement("attribute"); //$NON-NLS-1$ >+ attribute.setAttribute("name", "Main-Class"); //$NON-NLS-1$ //$NON-NLS-2$s >+ attribute.setAttribute("value", JIJConstants.LOADER_MAIN_CLASS); //$NON-NLS-1$ >+ manifest.appendChild(attribute); >+ >+ attribute= document.createElement("attribute"); //$NON-NLS-1$ >+ attribute.setAttribute("name", JIJConstants.REDIRECTED_MAIN_CLASS_MANIFEST_NAME); //$NON-NLS-1$ >+ attribute.setAttribute("value", mainClass); //$NON-NLS-1$ >+ manifest.appendChild(attribute); >+ >+ attribute= document.createElement("attribute"); //$NON-NLS-1$ >+ attribute.setAttribute("name", "Class-Path"); //$NON-NLS-1$ //$NON-NLS-2$s >+ attribute.setAttribute("value", "."); //$NON-NLS-1$ //$NON-NLS-2$ >+ manifest.appendChild(attribute); >+ >+ attribute= document.createElement("attribute"); //$NON-NLS-1$ >+ attribute.setAttribute("name", JIJConstants.REDIRECTED_CLASS_PATH_MANIFEST_NAME); //$NON-NLS-1$ >+ StringBuffer rsrcClassPath= new StringBuffer(); >+ rsrcClassPath.append(JIJConstants.CURRENT_DIR); >+ for (int i= 0; i < sourceInfos.length; i++) { >+ SourceInfo sourceInfo= sourceInfos[i]; >+ if (sourceInfo.isJar) { >+ rsrcClassPath.append(" ") //$NON-NLS-1$ >+ .append(new File(sourceInfo.absPath).getName()); >+ } >+ } >+ attribute.setAttribute("value", rsrcClassPath.toString()); //$NON-NLS-1$ >+ manifest.appendChild(attribute); >+ >+ Element zipfileset= document.createElement("zipfileset"); //$NON-NLS-1$ >+ zipfileset.setAttribute("src", FatJarRsrcUrlBuilder.JAR_RSRC_LOADER_ZIP); //$NON-NLS-1$ >+ jar.appendChild(zipfileset); >+ >+ for (int i= 0; i < sourceInfos.length; i++) { >+ SourceInfo sourceInfo= sourceInfos[i]; >+ File sourceFile = new File(sourceInfo.absPath); >+ String relativeParent= GetRelativePath(sourceFile.getParentFile(), antScriptFolder).toString(); >+ String relativeName= GetRelativePath(sourceFile, antScriptFolder).toString(); >+ >+ if (sourceInfo.isJar) { >+ Element fileset= document.createElement("zipfileset"); //$NON-NLS-1$ >+ fileset.setAttribute("dir", relativeParent); //$NON-NLS-1$ >+ fileset.setAttribute("includes", relativeName); //$NON-NLS-1$ >+ jar.appendChild(fileset); >+ } else { >+ Element fileset= document.createElement("fileset"); //$NON-NLS-1$ >+ fileset.setAttribute("dir", relativeName); //$NON-NLS-1$ >+ jar.appendChild(fileset); >+ } >+ } >+ >+ try { >+ // Write the document to the stream >+ Transformer transformer= TransformerFactory.newInstance().newTransformer(); >+ transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ >+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$ >+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ >+ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$ >+ DOMSource source= new DOMSource(document); >+ StreamResult result= new StreamResult(outputStream); >+ transformer.transform(source, result); >+ } catch (TransformerException e) { >+ throw new IOException(FatJarPackagerMessages.FatJarPackageAntScript_error_couldNotTransformToXML); >+ } >+ } finally { >+ if (outputStream != null) { >+ outputStream.close(); > } >- } >- >- try { >- // Write the document to the stream >- Transformer transformer= TransformerFactory.newInstance().newTransformer(); >- transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ >- transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$ >- transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ >- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$ >- DOMSource source= new DOMSource(document); >- StreamResult result= new StreamResult(outputStream); >- transformer.transform(source, result); >- } catch (TransformerException e) { >- throw new IOException(FatJarPackagerMessages.FatJarPackageAntScript_error_couldNotTransformToXML); > } > } > >+++ org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/jarpackagerfat/UnpackFatJarAntExporter.java Fri Oct 19 14:18:20 2012 >@@ -13,6 +13,7 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.jarpackagerfat; > >+import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > import java.io.OutputStream; >@@ -45,11 +46,15 @@ > } > > @Override >- protected void buildANTScript(IPath antScriptLocation, String projectName, IPath absJarfile, String mainClass, SourceInfo[] sourceInfos) throws IOException { >+ protected void buildANTScript(IPath antScriptLocation, String projectName, IPath jarFileLocation, String mainClass, SourceInfo[] sourceInfos) throws IOException { > OutputStream outputStream= null; >+ > try { >- outputStream= new FileOutputStream(antScriptLocation.toFile()); >- String absJarname= absJarfile.toString(); >+ File antScriptFile= antScriptLocation.toFile(); >+ File antScriptFolder= antScriptFile.getParentFile(); >+ outputStream= new FileOutputStream(antScriptFile); >+ >+ File jarFile= GetRelativePath(jarFileLocation.toFile(), antScriptFolder); > > DocumentBuilder docBuilder= null; > DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); >@@ -78,7 +83,7 @@ > project.appendChild(target); > > Element jar= document.createElement("jar"); //$NON-NLS-1$ >- jar.setAttribute("destfile", absJarname); //$NON-NLS-1$s >+ jar.setAttribute("destfile", jarFile.toString()); //$NON-NLS-1$s > jar.setAttribute("filesetmanifest", "mergewithoutmain"); //$NON-NLS-1$ //$NON-NLS-2$ > target.appendChild(jar); > >@@ -97,14 +102,17 @@ > > for (int i= 0; i < sourceInfos.length; i++) { > SourceInfo sourceInfo= sourceInfos[i]; >+ File sourceFile = new File(sourceInfo.absPath); >+ String relativeName= GetRelativePath(sourceFile, antScriptFolder).toString(); >+ > if (sourceInfo.isJar) { >- Element zipfileset= document.createElement("zipfileset"); //$NON-NLS-1$ >- zipfileset.setAttribute("src", sourceInfo.absPath); //$NON-NLS-1$ >- zipfileset.setAttribute("excludes", "META-INF/*.SF"); //$NON-NLS-1$ //$NON-NLS-2$ >- jar.appendChild(zipfileset); >+ Element fileset= document.createElement("zipfileset"); //$NON-NLS-1$ >+ fileset.setAttribute("src", relativeName); //$NON-NLS-1$ >+ fileset.setAttribute("excludes", "META-INF/*.SF"); //$NON-NLS-1$ //$NON-NLS-2$ >+ jar.appendChild(fileset); > } else { > Element fileset= document.createElement("fileset"); //$NON-NLS-1$ >- fileset.setAttribute("dir", sourceInfo.absPath); //$NON-NLS-1$ >+ fileset.setAttribute("dir", relativeName); //$NON-NLS-1$ > jar.appendChild(fileset); > } > } >+++ org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/jarpackagerfat/UnpackJarAntExporter.java Fri Oct 19 14:18:13 2012 >@@ -35,6 +35,7 @@ > import org.eclipse.core.runtime.IPath; > > import org.eclipse.debug.core.ILaunchConfiguration; >+import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarAntExporter.SourceInfo; > > /** > * Create an ANT script for a runnable JAR wit libraries in a sub-folder. The script is generated >@@ -49,13 +50,15 @@ > } > > @Override >- protected void buildANTScript(IPath antScriptLocation, String projectName, IPath absJarfile, String mainClass, SourceInfo[] sourceInfos) throws IOException { >+ protected void buildANTScript(IPath antScriptLocation, String projectName, IPath jarFileLocation, String mainClass, SourceInfo[] sourceInfos) throws IOException { > OutputStream outputStream= null; > try { >- outputStream= new FileOutputStream(antScriptLocation.toFile()); >- String absJarname= absJarfile.toString(); >- String subfolder= absJarfile.removeFileExtension().lastSegment() + "_lib"; //$NON-NLS-1$ >- String absSubfolder= absJarfile.removeLastSegments(1).append(subfolder).toString(); >+ File antScriptFile= antScriptLocation.toFile(); >+ File antScriptFolder= antScriptFile.getParentFile(); >+ outputStream= new FileOutputStream(antScriptFile); >+ >+ File jarFile= GetRelativePath(jarFileLocation.toFile(), antScriptFolder); >+ File jarSubfolder= GetRelativePath(new File(jarFileLocation.removeFileExtension() + "_lib"), antScriptFolder); > > DocumentBuilder docBuilder= null; > DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); >@@ -84,7 +87,7 @@ > project.appendChild(target); > > Element jar= document.createElement("jar"); //$NON-NLS-1$ >- jar.setAttribute("destfile", absJarname); //$NON-NLS-1$s >+ jar.setAttribute("destfile", jarFile.toString()); //$NON-NLS-1$s > target.appendChild(jar); > > Element manifest= document.createElement("manifest"); //$NON-NLS-1$ >@@ -102,7 +105,7 @@ > for (int i= 0; i < sourceInfos.length; i++) { > SourceInfo sourceInfo= sourceInfos[i]; > if (sourceInfo.isJar) { >- classPath.append(" ").append(subfolder).append("/") //$NON-NLS-1$ //$NON-NLS-2$ >+ classPath.append(" ").append(jarSubfolder).append("/") //$NON-NLS-1$ //$NON-NLS-2$ > .append(new File(sourceInfo.absPath).getName()); > } > } >@@ -112,29 +115,34 @@ > // add folders > for (int i= 0; i < sourceInfos.length; i++) { > SourceInfo sourceInfo= sourceInfos[i]; >+ > if (!sourceInfo.isJar) { >+ File sourceFile= new File(sourceInfo.absPath); >+ String relativeName= GetRelativePath(sourceFile, antScriptFolder).toString(); >+ > Element fileset= document.createElement("fileset"); //$NON-NLS-1$ >- fileset.setAttribute("dir", sourceInfo.absPath); //$NON-NLS-1$ >+ fileset.setAttribute("dir", relativeName); //$NON-NLS-1$ > jar.appendChild(fileset); > } > } > > > Element delete= document.createElement("delete"); //$NON-NLS-1$ >- delete.setAttribute("dir", absSubfolder); //$NON-NLS-1$s >+ delete.setAttribute("dir", jarSubfolder.toString()); //$NON-NLS-1$s > target.appendChild(delete); > > Element mkdir= document.createElement("mkdir"); //$NON-NLS-1$ >- mkdir.setAttribute("dir", absSubfolder); //$NON-NLS-1$s >+ mkdir.setAttribute("dir", jarSubfolder.toString()); //$NON-NLS-1$s > target.appendChild(mkdir); > > // add libraries > for (int i= 0; i < sourceInfos.length; i++) { > SourceInfo sourceInfo= sourceInfos[i]; > if (sourceInfo.isJar) { >+ File sourceFile= new File(sourceInfo.absPath); > Element copy= document.createElement("copy"); //$NON-NLS-1$ >- copy.setAttribute("file", sourceInfo.absPath); //$NON-NLS-1$ >- copy.setAttribute("todir", absSubfolder); //$NON-NLS-1$ >+ copy.setAttribute("file", GetRelativePath(sourceFile, antScriptFolder).toString()); //$NON-NLS-1$ >+ copy.setAttribute("todir", jarSubfolder.toString()); //$NON-NLS-1$ > target.appendChild(copy); > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 269201
:
129325
|
129326
|
132288
|
132476
|
222585
|
223065
|
244414