|
Lines 11-22
Link Here
|
| 11 |
* Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 220257 [jar application] ANT build file does not create Class-Path Entry in Manifest |
11 |
* Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 220257 [jar application] ANT build file does not create Class-Path Entry in Manifest |
| 12 |
* Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option |
12 |
* Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option |
| 13 |
* Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 262766 [jar exporter] ANT file for Jar-in-Jar option contains relative path to jar-rsrc-loader.zip |
13 |
* Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 262766 [jar exporter] ANT file for Jar-in-Jar option contains relative path to jar-rsrc-loader.zip |
|
|
14 |
* Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 269201 [jar exporter] ant file produced by Export runnable jar contains absolut paths instead of relative to workspace |
| 14 |
*******************************************************************************/ |
15 |
*******************************************************************************/ |
| 15 |
package org.eclipse.jdt.internal.ui.jarpackagerfat; |
16 |
package org.eclipse.jdt.internal.ui.jarpackagerfat; |
| 16 |
|
17 |
|
|
|
18 |
import java.io.File; |
| 17 |
import java.io.FileNotFoundException; |
19 |
import java.io.FileNotFoundException; |
| 18 |
import java.io.IOException; |
20 |
import java.io.IOException; |
| 19 |
import java.util.ArrayList; |
21 |
import java.util.ArrayList; |
|
|
22 |
import java.util.HashMap; |
| 23 |
import java.util.Map; |
| 24 |
|
| 25 |
import org.w3c.dom.Document; |
| 26 |
import org.w3c.dom.Element; |
| 27 |
import org.w3c.dom.Node; |
| 20 |
|
28 |
|
| 21 |
import org.eclipse.core.runtime.CoreException; |
29 |
import org.eclipse.core.runtime.CoreException; |
| 22 |
import org.eclipse.core.runtime.IPath; |
30 |
import org.eclipse.core.runtime.IPath; |
|
Lines 25-30
Link Here
|
| 25 |
import org.eclipse.core.runtime.Path; |
33 |
import org.eclipse.core.runtime.Path; |
| 26 |
import org.eclipse.core.runtime.Status; |
34 |
import org.eclipse.core.runtime.Status; |
| 27 |
|
35 |
|
|
|
36 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 37 |
|
| 28 |
import org.eclipse.debug.core.ILaunchConfiguration; |
38 |
import org.eclipse.debug.core.ILaunchConfiguration; |
| 29 |
|
39 |
|
| 30 |
import org.eclipse.jdt.internal.corext.util.Messages; |
40 |
import org.eclipse.jdt.internal.corext.util.Messages; |
|
Lines 47-52
Link Here
|
| 47 |
*/ |
57 |
*/ |
| 48 |
public abstract class FatJarAntExporter { |
58 |
public abstract class FatJarAntExporter { |
| 49 |
|
59 |
|
|
|
60 |
private static final String ANT_PROPERTYNAME_DIR_BUILDFILE= "dir.buildfile"; //$NON-NLS-1$ |
| 61 |
private static final String ANT_PROPERTYNAME_DIR_WORKSPACE= "dir.workspace"; //$NON-NLS-1$ |
| 62 |
private static final String ANT_PROPERTYNAME_DIR_JARFILE= "dir.jarfile"; //$NON-NLS-1$ |
| 63 |
|
| 64 |
private static final String ANT_PROPERTY_DIR_BUILDFILE= "${"+ANT_PROPERTYNAME_DIR_BUILDFILE+"}"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 65 |
private static final String ANT_PROPERTY_DIR_WORKSPACE= "${"+ANT_PROPERTYNAME_DIR_WORKSPACE+"}"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 66 |
private static final String ANT_PROPERTY_DIR_JARFILE= "${"+ANT_PROPERTYNAME_DIR_JARFILE+"}"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 67 |
|
| 50 |
protected static class SourceInfo { |
68 |
protected static class SourceInfo { |
| 51 |
|
69 |
|
| 52 |
public final boolean isJar; |
70 |
public final boolean isJar; |
|
Lines 60-69
Link Here
|
| 60 |
} |
78 |
} |
| 61 |
} |
79 |
} |
| 62 |
|
80 |
|
|
|
81 |
/** |
| 82 |
* Helper class for path-substitutions. |
| 83 |
* This class manages a set of path substitutions. |
| 84 |
* On apply the longest substitution is chosen. |
| 85 |
*/ |
| 86 |
private static class PathSubstituter { |
| 87 |
private Map<String, String> pathSubstitutions = new HashMap<String, String>(); |
| 88 |
public PathSubstituter addSubstitution(String basePath, String baseReplacement) { |
| 89 |
pathSubstitutions.put(basePath, baseReplacement); |
| 90 |
return this; |
| 91 |
} |
| 92 |
public String substitute(String path) { |
| 93 |
int len = 0; |
| 94 |
String result = path; |
| 95 |
for (String basePath:pathSubstitutions.keySet()) { |
| 96 |
if (basePath.length() < len) { |
| 97 |
continue; |
| 98 |
} |
| 99 |
if (path.equals(basePath)) { |
| 100 |
result = pathSubstitutions.get(basePath); |
| 101 |
break; |
| 102 |
} |
| 103 |
if (path.startsWith(basePath+File.separator)) { |
| 104 |
len = basePath.length(); |
| 105 |
result = pathSubstitutions.get(basePath)+path.substring(len); |
| 106 |
} |
| 107 |
} |
| 108 |
return result; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 63 |
private ILaunchConfiguration fLaunchConfiguration; |
112 |
private ILaunchConfiguration fLaunchConfiguration; |
| 64 |
private IPath fAbsJarfile; |
113 |
private IPath fAbsJarfile; |
| 65 |
private IPath fAntScriptLocation; |
114 |
private IPath fAntScriptLocation; |
| 66 |
|
115 |
|
|
|
116 |
private String fBuildfileDir; |
| 117 |
private String fWorkspaceDir; |
| 118 |
private String fJarfileDir; |
| 119 |
|
| 120 |
private PathSubstituter pathSubstituter; |
| 121 |
|
| 67 |
/** |
122 |
/** |
| 68 |
* Create an instance of the ANT exporter. An ANT exporter can generate an ANT script |
123 |
* Create an instance of the ANT exporter. An ANT exporter can generate an ANT script |
| 69 |
* at the given ant script location for the given launch configuration |
124 |
* at the given ant script location for the given launch configuration |
|
Lines 75-80
Link Here
|
| 75 |
fLaunchConfiguration= launchConfiguration; |
130 |
fLaunchConfiguration= launchConfiguration; |
| 76 |
fAbsJarfile= jarLocation; |
131 |
fAbsJarfile= jarLocation; |
| 77 |
fAntScriptLocation= antScriptLocation; |
132 |
fAntScriptLocation= antScriptLocation; |
|
|
133 |
pathSubstituter = new PathSubstituter(); |
| 134 |
try { |
| 135 |
fBuildfileDir = antScriptLocation.toFile().getParentFile().getCanonicalPath(); |
| 136 |
pathSubstituter.addSubstitution(fBuildfileDir, ANT_PROPERTY_DIR_BUILDFILE); |
| 137 |
} catch (Exception e) { |
| 138 |
JavaPlugin.log(e); |
| 139 |
fBuildfileDir= "?"; //$NON-NLS-1$ |
| 140 |
} |
| 141 |
try { |
| 142 |
fJarfileDir = jarLocation.toFile().getParentFile().getCanonicalPath(); |
| 143 |
pathSubstituter.addSubstitution(fJarfileDir, ANT_PROPERTY_DIR_JARFILE); |
| 144 |
} catch (Exception e) { |
| 145 |
JavaPlugin.log(e); |
| 146 |
fJarfileDir= "?"; //$NON-NLS-1$ |
| 147 |
} |
| 148 |
try { |
| 149 |
fWorkspaceDir= ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getCanonicalPath(); |
| 150 |
pathSubstituter.addSubstitution(fWorkspaceDir, ANT_PROPERTY_DIR_WORKSPACE); |
| 151 |
} catch (Exception e) { |
| 152 |
JavaPlugin.log(e); |
| 153 |
fWorkspaceDir= "?"; //$NON-NLS-1$ |
| 154 |
} |
| 78 |
} |
155 |
} |
| 79 |
|
156 |
|
| 80 |
/** |
157 |
/** |
|
Lines 164-169
Link Here
|
| 164 |
return result; |
241 |
return result; |
| 165 |
} |
242 |
} |
| 166 |
|
243 |
|
|
|
244 |
|
| 245 |
/** |
| 246 |
* add dir properties to ANT-Buildfile. |
| 247 |
* <ul> |
| 248 |
* <li><property name="dir.buildfile" value="." /></li> |
| 249 |
* <li><property name="dir.workspace" value="${dir.buildfile}/../.." /></li> |
| 250 |
* <li><property name="dir.jarfile" value="C:/TEMP" /></li> |
| 251 |
* </ul> |
| 252 |
* |
| 253 |
* @param document the dom document of the ant buildscript |
| 254 |
* @param project the project tag |
| 255 |
*/ |
| 256 |
protected void addBaseDirProperties(Document document, Element project) { |
| 257 |
|
| 258 |
Node comment= document.createComment("define folder properties"); //$NON-NLS-1$ |
| 259 |
project.appendChild(comment); |
| 260 |
|
| 261 |
Element property= document.createElement("property"); //$NON-NLS-1$ |
| 262 |
property.setAttribute("name", ANT_PROPERTYNAME_DIR_BUILDFILE); //$NON-NLS-1$ |
| 263 |
property.setAttribute("value", "."); //$NON-NLS-1$ //$NON-NLS-2$ |
| 264 |
project.appendChild(property); |
| 265 |
|
| 266 |
property= document.createElement("property"); //$NON-NLS-1$ |
| 267 |
property.setAttribute("name", ANT_PROPERTYNAME_DIR_WORKSPACE); //$NON-NLS-1$ |
| 268 |
property.setAttribute("value", getWorkspaceRelativeDir()); //$NON-NLS-1$ |
| 269 |
project.appendChild(property); |
| 270 |
|
| 271 |
property= document.createElement("property"); //$NON-NLS-1$ |
| 272 |
property.setAttribute("name", ANT_PROPERTYNAME_DIR_JARFILE); //$NON-NLS-1$ |
| 273 |
property.setAttribute("value", getJarfileRelativeDir()); //$NON-NLS-1$ |
| 274 |
project.appendChild(property); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
/** |
| 279 |
* Try to make the given filename relative to any of the ant-property-dirs. |
| 280 |
* <ul> |
| 281 |
* <li>buidfile-dir (where the ant script is)</li> |
| 282 |
* <li>workspace-dir (eclipse workspace dir)</li> |
| 283 |
* <li>jarfile-dir (where the jar is written to)</li> |
| 284 |
* </ul> |
| 285 |
* |
| 286 |
* @param absFilename filename whichs base dir is substituted |
| 287 |
* @return either the original filename or a relative path from one of the base-dirs |
| 288 |
*/ |
| 289 |
protected String substituteBaseDirs(String absFilename) { |
| 290 |
String canonicleFilename; |
| 291 |
try { |
| 292 |
canonicleFilename= new File(absFilename).getCanonicalPath(); |
| 293 |
} catch (IOException e) { |
| 294 |
e.printStackTrace(); |
| 295 |
return absFilename; |
| 296 |
} |
| 297 |
String result = pathSubstituter.substitute(canonicleFilename); |
| 298 |
result = result.replace(File.separatorChar, '/'); |
| 299 |
return result; |
| 300 |
} |
| 301 |
|
| 302 |
/** |
| 303 |
* @return workspace-dir relative to buildfile-dir if possible |
| 304 |
*/ |
| 305 |
protected String getWorkspaceRelativeDir() { |
| 306 |
String result; |
| 307 |
if (fBuildfileDir.startsWith(fWorkspaceDir+File.separator)) { |
| 308 |
int lastSlash = fWorkspaceDir.length(); |
| 309 |
result = "${dir.buildfile}"+File.separator+".."; //$NON-NLS-1$ //$NON-NLS-2$ |
| 310 |
lastSlash = fBuildfileDir.indexOf(File.separator, lastSlash+1); |
| 311 |
while (lastSlash != -1) { |
| 312 |
result += File.separator+".."; //$NON-NLS-1$ |
| 313 |
lastSlash = fBuildfileDir.indexOf(File.separator, lastSlash+1); |
| 314 |
} |
| 315 |
} |
| 316 |
else { |
| 317 |
result = new PathSubstituter() |
| 318 |
.addSubstitution(fBuildfileDir, ANT_PROPERTY_DIR_BUILDFILE) |
| 319 |
.substitute(fWorkspaceDir); |
| 320 |
} |
| 321 |
result = result.replace(File.separatorChar, '/'); |
| 322 |
return result; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
/** |
| 327 |
* @return jarfile-dir relative to buildfile-dir or workspace-dir if possible |
| 328 |
*/ |
| 329 |
protected String getJarfileRelativeDir() { |
| 330 |
String result = new PathSubstituter() |
| 331 |
.addSubstitution(fBuildfileDir, ANT_PROPERTY_DIR_BUILDFILE) |
| 332 |
.addSubstitution(fWorkspaceDir, ANT_PROPERTY_DIR_WORKSPACE) |
| 333 |
.substitute(fJarfileDir); |
| 334 |
result = result.replace(File.separatorChar, '/'); |
| 335 |
return result; |
| 336 |
} |
| 337 |
|
| 338 |
|
| 167 |
/** |
339 |
/** |
| 168 |
* Create an ANT script at the given location. |
340 |
* Create an ANT script at the given location. |
| 169 |
* |
341 |
* |