本文整理匯總了Java中org.netbeans.spi.project.support.ant.PropertyUtils.relativizeFile方法的典型用法代碼示例。如果您正苦於以下問題:Java PropertyUtils.relativizeFile方法的具體用法?Java PropertyUtils.relativizeFile怎麽用?Java PropertyUtils.relativizeFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.netbeans.spi.project.support.ant.PropertyUtils
的用法示例。
在下文中一共展示了PropertyUtils.relativizeFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: browseLicense
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
private void browseLicense(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLicense
String startDir;
File currentLicenceF = getCurrentLicenceFile();
if (currentLicenceF != null && currentLicenceF.exists() && currentLicenceF.getParent() != null) {
startDir = currentLicenceF.getParent();
} else {
startDir = getProperties().getProjectDirectory();
}
JFileChooser chooser = new JFileChooser(startDir);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int ret = chooser.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
File f = chooser.getSelectedFile();
String relPath = PropertyUtils.relativizeFile(getProperties().getProjectDirectoryFile(), f);
licenseValue.setText(relPath != null ? relPath : f.getAbsolutePath());
}
}
示例2: browseButtonActionPerformed
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastUsedClusterLocation());
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int ret = chooser.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
File file = FileUtil.normalizeFile(chooser.getSelectedFile());
AGAIN: for (;;) {
if (! file.exists() || file.isFile() || ! ClusterUtils.isValidCluster(file)) {
if (Clusterize.clusterize(prj, file)) {
continue AGAIN;
}
} else {
ModuleUISettings.getDefault().setLastUsedClusterLocation(file.getParentFile().getAbsolutePath());
String relPath = PropertyUtils.relativizeFile(prjDir, file);
clusterDirText.setText(relPath != null ? relPath : file.getAbsolutePath());
}
break;
}
}
}
示例3: createSuiteProperties
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
/**
* Detects whether <code>projectDir</code> is relative to
* <code>suiteDir</code> and creates <em>nbproject/suite.properties</em> or
* <em>nbproject/private/suite-private.properties</em> with
* <em>suite.dir</em> appropriately set.
*/
public static void createSuiteProperties(FileObject projectDir, File suiteDir) throws IOException {
File projectDirF = FileUtil.toFile(projectDir);
String suiteLocation;
String suitePropertiesLocation;
//mkleint: removed CollocationQuery.areCollocated() reference
// when AlwaysRelativeCQI gets removed the condition resolves to false more frequently.
// that might not be desirable.
String rel = PropertyUtils.relativizeFile(projectDirF, suiteDir);
if (rel != null) {
suiteLocation = "${basedir}/" + rel; // NOI18N
suitePropertiesLocation = "nbproject/suite.properties"; // NOI18N
} else {
suiteLocation = suiteDir.getAbsolutePath();
suitePropertiesLocation = "nbproject/private/suite-private.properties"; // NOI18N
}
EditableProperties props = new EditableProperties(true);
props.setProperty("suite.dir", suiteLocation); // NOI18N
FileObject suiteProperties = projectDir.getFileObject(suitePropertiesLocation);
if (suiteProperties == null || !suiteProperties.isValid()) {
suiteProperties = createFileObject(projectDir, suitePropertiesLocation);
}
Util.storeProperties(suiteProperties, props);
}
示例4: updateReference
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
private void updateReference(String value, String key, boolean main) {
File absFile = ahelper.resolveFile(value);
String newVal = relative ? PropertyUtils.relativizeFile(FileUtil.toFile(ahelper.getProjectDirectory()), absFile) : absFile.getAbsolutePath();
if (newVal == null) {
//fallback
newVal = absFile.getAbsolutePath();
}
if (!newVal.equals(value)) {
if (main) {
refhelper.createForeignFileReferenceAsIs(newVal, key);
} else {
refhelper.createExtraForeignFileReferenceAsIs(newVal, key);
}
}
}
示例5: getArtifactLocations
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
public URI[] getArtifactLocations() {
String jarloc = eval.evaluate("${cluster}/${module.jar}"); // NOI18N
File jar = helper.resolveFile(jarloc); // probably absolute anyway, now
String reldir = PropertyUtils.relativizeFile(project.getProjectDirectoryFile(), jar);
if (reldir != null) {
try {
return new URI[] {new URI(null, null, reldir, null)};
} catch (URISyntaxException e) {
throw new AssertionError(e);
}
} else {
return new URI[] {Utilities.toURI(jar)};
}
// XXX should it add in class path extensions?
}
示例6: attachSubModuleToSuite
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
private void attachSubModuleToSuite(NbModuleProject subModule) throws IOException {
// adjust suite project's properties
File projectDirF = FileUtil.toFile(subModule.getProjectDirectory());
File suiteDirF = suiteProps.getProjectDirectoryFile();
String projectPropKey = generatePropertyKey(subModule);
String rel = PropertyUtils.relativizeFile(suiteDirF, projectDirF);
//mkleint: removed CollocationQuery.areCollocated() reference
// when AlwaysRelativeCQI gets removed the condition resolves to false more frequently.
// that might not be desirable.
if (rel != null) {
suiteProps.setProperty(projectPropKey,
rel);
} else {
suiteProps.setPrivateProperty(projectPropKey, projectDirF.getAbsolutePath());
}
String origModules = suiteProps.getProperty(MODULES_PROPERTY);
StringBuilder modules = new StringBuilder(origModules == null ? "" : origModules);
if (modules.length() > 0) {
modules.append(':');
}
modules.append("${").append(projectPropKey).append('}'); // NOI18N
suiteProps.setProperty(MODULES_PROPERTY, modules.toString().split("(?<=:)", -1)); // NOI18N
// adjust subModule's properties
NbModuleProjectGenerator.createSuiteProperties(subModule.getProjectDirectory(), suiteDirF);
setNbModuleType(subModule, NbModuleType.SUITE_COMPONENT);
ProjectManager.getDefault().saveProject(subModule);
}
示例7: getIconLocation
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
protected final @CheckForNull String getIconLocation() {
if (icon48 == null) {
return null;
}
File prj = getProjectDirectoryFile();
String relativePath = PropertyUtils.relativizeFile(prj, icon48.getFileLocation());
return relativePath;
}
示例8: fixLibraryLocation
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
private void fixLibraryLocation(Operations original) throws IllegalArgumentException {
String libPath = original.libraryPath;
if (libPath != null) {
if (!new File(libPath).isAbsolute()) {
//relative path to libraries
if (!original.libraryWithinProject) {
File file = original.libraryFile;
if (file == null) {
// could happen in some rare cases, but in that case the original project was already broken, don't fix.
return;
}
String relativized = PropertyUtils.relativizeFile(FileUtil.toFile(project.getProjectDirectory()), file);
if (relativized != null) {
helper.getAntProjectHelper().setLibrariesLocation(relativized);
} else {
//cannot relativize, use absolute path
helper.getAntProjectHelper().setLibrariesLocation(file.getAbsolutePath());
}
} else {
//got copied over to new location.. the relative path is the same..
}
} else {
//absolute path to libraries..
if (original.libraryWithinProject) {
if (original.absolutesRelPath != null) {
helper.getAntProjectHelper().setLibrariesLocation(PropertyUtils.resolveFile(FileUtil.toFile(project.getProjectDirectory()), original.absolutesRelPath).getAbsolutePath());
}
} else {
// absolute path to an external folder stays the same.
}
}
}
}
示例9: store
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
public void store() throws IOException {
Preferences prefs = prefs(suiteProject);
prefs.putBoolean(GENERATE_FOR_WINDOWS, windowsModel.isSelected());
prefs.putBoolean(GENERATE_FOR_LINUX, linuxModel.isSelected());
prefs.putBoolean(GENERATE_FOR_SOLARIS, solarisModel.isSelected());
prefs.putBoolean(GENERATE_FOR_MAC, macModel.isSelected());
prefs.putBoolean(USE_PACK200_COMPRESSION, pack200Model.isSelected());
String licenseName = (String) licenseModel.getSelectedItem();
if (licenseName != null) {
int index = licenseModel.getNames().indexOf(licenseName);
if (index != -1) {
String type = licenseModel.getTypes().get(index);
if (type.equals(LICENSE_TYPE_FILE)) {
File suiteLocation = FileUtil.toFile(suiteProject.getProjectDirectory());
File f = PropertyUtils.resolveFile(suiteLocation, licenseName);
String rel = PropertyUtils.relativizeFile(suiteLocation, f);
if (rel != null) {
prefs.put(LICENSE_FILE, rel);
} else {
prefs.put(LICENSE_FILE, f.getAbsolutePath());
}
prefs.remove(LICENSE_TYPE);
} else {
prefs.put(LICENSE_TYPE, type);
prefs.remove(LICENSE_FILE);
}
}
}
}
示例10: relativizeLocation
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
/**
* Relativize given file against the original project and if needed use
* ${project.dir} property as base. If file cannot be relativized
* the absolute filepath is returned.
* @param projectBase original project base folder
* @param freeformBase Freeform project base folder
* @param location location to relativize
* @return text suitable for storage in project.xml representing given location
*/
public static String relativizeLocation(File projectBase, File freeformBase, File location) {
if (CollocationQuery.areCollocated(projectBase, location)) {
if (projectBase.equals(freeformBase)) {
return PropertyUtils.relativizeFile(projectBase, location);
} else if (projectBase.equals(location) && ProjectConstants.PROJECT_LOCATION_PREFIX.endsWith("/")) { // NOI18N
return ProjectConstants.PROJECT_LOCATION_PREFIX.substring(0, ProjectConstants.PROJECT_LOCATION_PREFIX.length() - 1);
} else {
return ProjectConstants.PROJECT_LOCATION_PREFIX + PropertyUtils.relativizeFile(projectBase, location);
}
} else {
return location.getAbsolutePath();
}
}
示例11: getRelativeFiles
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
private List<String> getRelativeFiles(List<File> files) {
List<String> fs = new ArrayList<String>();
for (File file : files) {
String s = PropertyUtils.relativizeFile(baseFolder, file);
if (s != null) {
fs.add(s);
}
}
return fs;
}
示例12: makeRelative
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
private static String makeRelative(AntProjectHelper helper, String path) {
File f = new File(path);
if (!f.isAbsolute()) {
return path;
}
File proj = FileUtil.toFile(helper.getProjectDirectory());
if (CollocationQuery.areCollocated(f, proj)) {
String relativePath = PropertyUtils.relativizeFile(proj, f);
if (relativePath != null) {
return relativePath;
}
}
return path;
}
示例13: getRelativePath
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
@Override public String getRelativePath() {
return PropertyUtils.relativizeFile(mEntry.getClusterDirectory(), mEntry.getJarLocation());
}
示例14: findClusterLocation
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
/**
* Find cluster location of a netbeans module (standalone, suite components and NB.org).
* @param basedir project basedir
* @param nbroot location of netbeans.org source root; not used for standalone modules and suite components
*/
public static String findClusterLocation(File basedir, File nbroot, NbModuleType type) throws IOException {
String cluster;
switch (type) {
case SUITE_COMPONENT:
cluster = "${suite.build.dir}/cluster"; // NOI18N
break;
case STANDALONE:
cluster = "${build.dir}/cluster"; // NOI18N
break;
case NETBEANS_ORG:
default:
String path = PropertyUtils.relativizeFile(nbroot, basedir);
// #163744: can happen with symlinks assert path.indexOf("..") == -1 : path;
Map<String,String> clusterLocationsHere = clusterLocations.get(nbroot);
if (clusterLocationsHere == null) {
clusterLocationsHere = new HashMap<String,String>();
Map<String,String> clusterDefs = getClusterProperties(nbroot);
for (Map.Entry<String,String> entry : clusterDefs.entrySet()) {
String key = entry.getKey();
String clusterDir = clusterDefs.get(key + ".dir"); // NOI18N
if (clusterDir == null) {
// Not a list of modules.
// XXX could also just read clusters.list
continue;
}
String val = entry.getValue();
StringTokenizer tok = new StringTokenizer(val, ", "); // NOI18N
while (tok.hasMoreTokens()) {
String p = tok.nextToken();
clusterLocationsHere.put(p, clusterDir);
}
}
clusterLocations.put(nbroot, clusterLocationsHere);
}
cluster = clusterLocationsHere.get(path);
if (cluster == null) {
cluster = "extra"; // NOI18N
}
cluster = "${netbeans.dest.dir}/" + cluster;
}
return cluster;
}
示例15: appendToSuite
import org.netbeans.spi.project.support.ant.PropertyUtils; //導入方法依賴的package包/類
/**
* Appends currently created project in the <code>projectDir<code> to a
* suite project contained in the <code>suiteDir</code>. Also intelligently
* decides whether an added project is relative to a destination suite or
* absolute and uses either <em>nbproject/project.properties</em> or
* <em>nbproject/private/private.properties</em> appropriately.
*/
private static void appendToSuite(String cnb, FileObject projectDir, File suiteDir) throws IOException {
File projectDirF = FileUtil.toFile(projectDir);
File suiteGlobalPropsFile = new File(suiteDir, "nbproject/project.properties"); // NOI18N
FileObject suiteGlobalPropFO;
if (suiteGlobalPropsFile.exists()) {
suiteGlobalPropFO = FileUtil.toFileObject(suiteGlobalPropsFile);
} else {
suiteGlobalPropFO = createFileObject(suiteGlobalPropsFile);
}
EditableProperties globalProps = Util.loadProperties(suiteGlobalPropFO);
String projectPropKey = "project." + cnb; // NOI18N
String rel = PropertyUtils.relativizeFile(suiteDir, projectDirF);
//mkleint: removed CollocationQuery.areCollocated() reference
// when AlwaysRelativeCQI gets removed the condition resolves to false more frequently.
// that might not be desirable.
if (rel != null) {
globalProps.setProperty(projectPropKey,
rel);
} else {
File suitePrivPropsFile = new File(suiteDir, "nbproject/private/private.properties"); // NOI18N
FileObject suitePrivPropFO;
if (suitePrivPropsFile.exists()) {
suitePrivPropFO = FileUtil.toFileObject(suitePrivPropsFile);
} else {
suitePrivPropFO = createFileObject(suitePrivPropsFile);
}
EditableProperties privProps= Util.loadProperties(suitePrivPropFO);
privProps.setProperty(projectPropKey, projectDirF.getAbsolutePath());
Util.storeProperties(suitePrivPropFO, privProps);
}
String modulesProp = globalProps.getProperty("modules"); // NOI18N
if (modulesProp == null) {
modulesProp = "";
}
if (modulesProp.length() > 0) {
modulesProp += ":"; // NOI18N
}
modulesProp += "${" + projectPropKey + "}"; // NOI18N
globalProps.setProperty("modules", modulesProp.split("(?<=:)", -1)); // NOI18N
Util.storeProperties(suiteGlobalPropFO, globalProps);
}