|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2007, 2011 IBM Corporation and others. |
2 |
* Copyright (c) 2007, 2014 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
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 24-29
Link Here
|
| 24 |
import org.eclipse.core.runtime.MultiStatus; |
32 |
import org.eclipse.core.runtime.MultiStatus; |
| 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; |
|
|
35 |
|
| 36 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 27 |
|
37 |
|
| 28 |
import org.eclipse.debug.core.ILaunchConfiguration; |
38 |
import org.eclipse.debug.core.ILaunchConfiguration; |
| 29 |
|
39 |
|
|
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 |
|
| 89 |
public PathSubstituter addSubstitution(String basePath, String baseReplacement) { |
| 90 |
pathSubstitutions.put(basePath, baseReplacement); |
| 91 |
return this; |
| 92 |
} |
| 93 |
|
| 94 |
public String substitute(String path) { |
| 95 |
int len= 0; |
| 96 |
String result= path; |
| 97 |
for (String basePath : pathSubstitutions.keySet()) { |
| 98 |
if (basePath.length() < len) { |
| 99 |
continue; |
| 100 |
} |
| 101 |
if (path.equals(basePath)) { |
| 102 |
result= pathSubstitutions.get(basePath); |
| 103 |
break; |
| 104 |
} |
| 105 |
if (path.startsWith(basePath + File.separator)) { |
| 106 |
len= basePath.length(); |
| 107 |
result= pathSubstitutions.get(basePath) + path.substring(len); |
| 108 |
} |
| 109 |
} |
| 110 |
return result; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 63 |
private ILaunchConfiguration fLaunchConfiguration; |
114 |
private ILaunchConfiguration fLaunchConfiguration; |
| 64 |
private IPath fAbsJarfile; |
115 |
private IPath fAbsJarfile; |
| 65 |
private IPath fAntScriptLocation; |
116 |
private IPath fAntScriptLocation; |
| 66 |
|
117 |
|
|
|
118 |
private String fBuildfileDir; |
| 119 |
private String fWorkspaceDir; |
| 120 |
private String fJarfileDir; |
| 121 |
|
| 122 |
private PathSubstituter pathSubstituter; |
| 123 |
|
| 67 |
/** |
124 |
/** |
| 68 |
* Create an instance of the ANT exporter. An ANT exporter can generate an ANT script |
125 |
* 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 |
126 |
* at the given ant script location for the given launch configuration |
|
Lines 75-80
Link Here
|
| 75 |
fLaunchConfiguration= launchConfiguration; |
132 |
fLaunchConfiguration= launchConfiguration; |
| 76 |
fAbsJarfile= jarLocation; |
133 |
fAbsJarfile= jarLocation; |
| 77 |
fAntScriptLocation= antScriptLocation; |
134 |
fAntScriptLocation= antScriptLocation; |
|
|
135 |
pathSubstituter= new PathSubstituter(); |
| 136 |
try { |
| 137 |
fBuildfileDir= antScriptLocation.toFile().getParentFile().getCanonicalPath(); |
| 138 |
pathSubstituter.addSubstitution(fBuildfileDir, ANT_PROPERTY_DIR_BUILDFILE); |
| 139 |
} catch (Exception e) { |
| 140 |
JavaPlugin.log(e); |
| 141 |
fBuildfileDir= "?"; //$NON-NLS-1$ |
| 142 |
} |
| 143 |
try { |
| 144 |
fJarfileDir= jarLocation.toFile().getParentFile().getCanonicalPath(); |
| 145 |
pathSubstituter.addSubstitution(fJarfileDir, ANT_PROPERTY_DIR_JARFILE); |
| 146 |
} catch (Exception e) { |
| 147 |
JavaPlugin.log(e); |
| 148 |
fJarfileDir= "?"; //$NON-NLS-1$ |
| 149 |
} |
| 150 |
try { |
| 151 |
fWorkspaceDir= ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getCanonicalPath(); |
| 152 |
pathSubstituter.addSubstitution(fWorkspaceDir, ANT_PROPERTY_DIR_WORKSPACE); |
| 153 |
} catch (Exception e) { |
| 154 |
JavaPlugin.log(e); |
| 155 |
fWorkspaceDir= "?"; //$NON-NLS-1$ |
| 156 |
} |
| 78 |
} |
157 |
} |
| 79 |
|
158 |
|
| 80 |
/** |
159 |
/** |
|
Lines 98-112
Link Here
|
| 98 |
new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, |
177 |
new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, |
| 99 |
Messages.format(FatJarPackagerMessages.FatJarPackageWizard_antScript_error_readingOutputFile, new Object[] { |
178 |
Messages.format(FatJarPackagerMessages.FatJarPackageWizard_antScript_error_readingOutputFile, new Object[] { |
| 100 |
BasicElementLabels.getPathLabel(fAntScriptLocation, true), e.getLocalizedMessage() }) |
179 |
BasicElementLabels.getPathLabel(fAntScriptLocation, true), e.getLocalizedMessage() }) |
| 101 |
) |
180 |
)); |
| 102 |
); |
|
|
| 103 |
} catch (IOException e) { |
181 |
} catch (IOException e) { |
| 104 |
throw new CoreException( |
182 |
throw new CoreException( |
| 105 |
new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, |
183 |
new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, |
| 106 |
Messages.format(FatJarPackagerMessages.FatJarPackageWizard_antScript_error_writingOutputFile, new Object[] { |
184 |
Messages.format(FatJarPackagerMessages.FatJarPackageWizard_antScript_error_writingOutputFile, new Object[] { |
| 107 |
BasicElementLabels.getPathLabel(fAntScriptLocation, true), e.getLocalizedMessage() }) |
185 |
BasicElementLabels.getPathLabel(fAntScriptLocation, true), e.getLocalizedMessage() }) |
| 108 |
) |
186 |
)); |
| 109 |
); |
|
|
| 110 |
} |
187 |
} |
| 111 |
} |
188 |
} |
| 112 |
|
189 |
|
|
Lines 164-169
Link Here
|
| 164 |
return result; |
241 |
return result; |
| 165 |
} |
242 |
} |
| 166 |
|
243 |
|
|
|
244 |
|
| 245 |
/** |
| 246 |
* Adds 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 build script |
| 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 |
* Converts 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 whose 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 |
* Returns the workspace-dir path relative to buildfile-dir. |
| 304 |
* |
| 305 |
* @return the relative path for the workspace-dir |
| 306 |
*/ |
| 307 |
protected String getWorkspaceRelativeDir() { |
| 308 |
String result; |
| 309 |
if (fBuildfileDir.startsWith(fWorkspaceDir + File.separator)) { |
| 310 |
int lastSlash= fWorkspaceDir.length(); |
| 311 |
result= "${dir.buildfile}" + File.separator + ".."; //$NON-NLS-1$ //$NON-NLS-2$ |
| 312 |
lastSlash= fBuildfileDir.indexOf(File.separator, lastSlash + 1); |
| 313 |
while (lastSlash != -1) { |
| 314 |
result+= File.separator + ".."; //$NON-NLS-1$ |
| 315 |
lastSlash= fBuildfileDir.indexOf(File.separator, lastSlash + 1); |
| 316 |
} |
| 317 |
} |
| 318 |
else { |
| 319 |
result= new PathSubstituter() |
| 320 |
.addSubstitution(fBuildfileDir, ANT_PROPERTY_DIR_BUILDFILE) |
| 321 |
.substitute(fWorkspaceDir); |
| 322 |
} |
| 323 |
result= result.replace(File.separatorChar, '/'); |
| 324 |
return result; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
/** |
| 329 |
* Returns jarfile-dir path relative to buildfile-dir or workspace-dir. |
| 330 |
* |
| 331 |
* @return the relative path for the jarfile-dir |
| 332 |
*/ |
| 333 |
protected String getJarfileRelativeDir() { |
| 334 |
String result= new PathSubstituter() |
| 335 |
.addSubstitution(fBuildfileDir, ANT_PROPERTY_DIR_BUILDFILE) |
| 336 |
.addSubstitution(fWorkspaceDir, ANT_PROPERTY_DIR_WORKSPACE) |
| 337 |
.substitute(fJarfileDir); |
| 338 |
result= result.replace(File.separatorChar, '/'); |
| 339 |
return result; |
| 340 |
} |
| 341 |
|
| 342 |
|
| 167 |
/** |
343 |
/** |
| 168 |
* Create an ANT script at the given location. |
344 |
* Create an ANT script at the given location. |
| 169 |
* |
345 |
* |