Java Code Examples for org.eclipse.core.runtime.IPath#addFileExtension()

The following examples show how to use org.eclipse.core.runtime.IPath#addFileExtension() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeScriptSourceMapLanguageSupport.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
public IPath getSourceMapFile(IPath tsFilePath) {
	// Search js file in the same folder than ts file.
	IPath jsMapFilePath = tsFilePath.removeFileExtension().addFileExtension("js.map");
	IFile jsMapFile = WorkbenchResourceUtil.findFileFromWorkspace(jsMapFilePath);
	if (jsMapFile != null) {
		return jsMapFilePath;
	}
	// Search js file in the well folder by using tsconfig.json
	IFile tsFile = WorkbenchResourceUtil.findFileFromWorkspace(tsFilePath);
	try {
		IDETsconfigJson tsconfig = TypeScriptResourceUtil.findTsconfig(tsFile);
		if (tsconfig != null) {
			IContainer configOutDir = tsconfig.getOutDir();
			if (configOutDir != null && configOutDir.exists()) {
				IPath tsFileNamePath = WorkbenchResourceUtil.getRelativePath(tsFile, configOutDir)
						.removeFileExtension();
				return tsFileNamePath.addFileExtension("js");
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 2
Source File: CommonJSResolver.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public IPath resolve(String moduleId, IProject project, IPath currentLocation, IPath indexRoot)
{
	if (!currentLocation.toFile().isDirectory())
	{
		throw new IllegalArgumentException("current location must be a directory"); //$NON-NLS-1$
	}
	if (!indexRoot.toFile().isDirectory())
	{
		throw new IllegalArgumentException("module namespace root must be a directory"); //$NON-NLS-1$
	}

	IPath modulePath = Path.fromPortableString(moduleId);
	if (modulePath.getFileExtension() == null)
	{
		modulePath = modulePath.addFileExtension("js"); //$NON-NLS-1$
	}
	if (moduleId.startsWith(".")) //$NON-NLS-1$
	{
		// relative
		return currentLocation.append(modulePath);
	}
	// absolute, so resolve releative to index root
	return indexRoot.append(modulePath);
}
 
Example 3
Source File: AbstractRequireResolver.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
protected IPath loadAsFile(IPath x, String... extensions)
{
	File file = x.toFile();
	if (file.isFile())
	{
		return x;
	}

	List<String> ext = CollectionsUtil.newList(extensions);
	ext.add(0, JS);

	for (String extension : ext)
	{
		IPath js = x.addFileExtension(extension);
		if (js.toFile().isFile())
		{
			return js;
		}
	}

	return null;
}
 
Example 4
Source File: ExecutableUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static IPath findExecutable(IPath basename, boolean appendExtension)
{
	if (Platform.OS_WIN32.equals(Platform.getOS()) && appendExtension)
	{
		String[] extensions = System.getenv(PATHEXT).split(File.pathSeparator);
		for (String ext : extensions)
		{
			if (ext.length() > 0 && ext.charAt(0) == '.')
			{
				ext = ext.substring(1);
			}
			IPath pathWithExt = basename.addFileExtension(ext);
			if (isExecutable(pathWithExt))
			{
				return pathWithExt;
			}
		}

	}
	else if (isExecutable(basename))
	{
		return basename;
	}
	return null;
}
 
Example 5
Source File: TypeScriptSourceMapLanguageSupport.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
public IPath getJsFile(IPath tsFilePath) {
	// Search js file in the same folder than ts file.
	IPath jsFilePath = tsFilePath.removeFileExtension().addFileExtension("js");
	IFile jsFile = WorkbenchResourceUtil.findFileFromWorkspace(jsFilePath);
	if (jsFile != null) {
		return jsFilePath;
	}
	// Search js file in the well folder by using tsconfig.json
	IFile tsFile = WorkbenchResourceUtil.findFileFromWorkspace(tsFilePath);
	try {
		IDETsconfigJson tsconfig = TypeScriptResourceUtil.findTsconfig(tsFile);
		if (tsconfig != null) {
			IContainer configOutDir = tsconfig.getOutDir();
			if (configOutDir != null && configOutDir.exists()) {
				IPath tsFileNamePath = WorkbenchResourceUtil.getRelativePath(tsFile, configOutDir)
						.removeFileExtension();
				return tsFileNamePath.addFileExtension("js");
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 6
Source File: WorkspaceTools.java    From depan with Apache License 2.0 5 votes vote down vote up
/**
 * Ensure that we have a file extension on the file name.
 * 
 * @param savePath Initial save path from user
 * @return valid IFile with an extension.
 */
public static IFile calcFileWithExt(IFile saveFile, String ext) {
  IPath savePath = saveFile.getFullPath();
  String saveExt = savePath.getFileExtension();
  if (null == saveExt) {
    savePath = savePath.addFileExtension(ext);
  } else if (!saveExt.equals(ext)) {
    savePath = savePath.addFileExtension(ext);
  }
  return buildResourceFile(savePath);
}
 
Example 7
Source File: WorkspaceTools.java    From depan with Apache License 2.0 5 votes vote down vote up
/**
 * Ensure that we have a file extension on the file name.
 * 
 * @param savePath Initial save path from user
 * @return valid IFile with an extension.
 */
public static IFile calcViewFile(IPath savePath, String ext) {
  String saveExt = savePath.getFileExtension();
  if (null == saveExt) {
    savePath = savePath.addFileExtension(ext);
  } else if (!saveExt.equals(ext)) {
    savePath = savePath.addFileExtension(ext);
  }
  return buildResourceFile(savePath);
}
 
Example 8
Source File: AbstractNewFileWizard.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Ensure the new file's name ends with the default file extension.
 * 
 * @return the filename ending with the file extension
 */
private IPath getNormalizedFilePath() {
  IPath newFilePath = getFilePath();
  String newFilename = newFilePath.lastSegment();
  String ext = getFileExtension();
  if (ext != null && ext.length() != 0) {
    if (!(newFilename.endsWith("." + ext))) {
      return newFilePath.addFileExtension(ext);
    }
  }

  return newFilePath;
}
 
Example 9
Source File: NewModuleWizardPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
protected IPath getModulePath() {
  IPackageFragmentRoot root = getPackageFragmentRoot();
  IPath rootPath = root.getPath();

  String packageName = getModulePackageName();
  if (packageName != null && packageName.length() > 0) {
    rootPath = rootPath.append(packageName.replace('.', '/'));
  }

  IPath moduleFilePath = rootPath.append(getModuleName());

  moduleFilePath = moduleFilePath.addFileExtension("gwt.xml");

  return moduleFilePath;
}
 
Example 10
Source File: SaveLoadConfig.java    From depan with Apache License 2.0 5 votes vote down vote up
private IFile guessSaveAsFile(IProject proj, String rsrcName) {
  IPath namePath = Path.fromOSString(rsrcName);
  namePath.addFileExtension(getExension());

  IPath treePath = getContainer().getPath();
  IPath destPath = treePath.append(namePath);
  return proj.getFile(destPath);
}
 
Example 11
Source File: TypeScriptResourceUtil.java    From typescript.java with MIT License 5 votes vote down vote up
public static void refreshAndCollectEmittedFiles(IFile tsFile, IDETsconfigJson tsconfig, boolean refresh,
		List<IFile> emittedFiles) throws CoreException {
	IContainer baseDir = tsFile.getParent();
	// Set outDir with the folder of the ts file.
	IContainer outDir = tsFile.getParent();
	if (tsconfig != null) {
		// tsconfig.json exists and "outDir" is setted, set "outDir" with
		// the tsconfig.json/compilerOption/outDir
		IContainer configOutDir = tsconfig.getOutDir();
		if (configOutDir != null && configOutDir.exists()) {
			outDir = configOutDir;
		}
	}

	IPath tsFileNamePath = WorkbenchResourceUtil.getRelativePath(tsFile, baseDir).removeFileExtension();
	// Refresh *.js file
	IPath jsFilePath = tsFileNamePath.addFileExtension(FileUtils.JS_EXTENSION);
	refreshAndCollectEmittedFile(jsFilePath, outDir, refresh, emittedFiles);
	// Refresh *.js.map file
	IPath jsMapFilePath = tsFileNamePath.addFileExtension(FileUtils.JS_EXTENSION)
			.addFileExtension(FileUtils.MAP_EXTENSION);
	refreshAndCollectEmittedFile(jsMapFilePath, outDir, refresh, emittedFiles);
	// Refresh ts file
	if (refresh) {
		refreshFile(tsFile, false);
	}
}
 
Example 12
Source File: AbstractJarDestinationWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void updateModel() {
	// destination
	String comboText= fDestinationNamesCombo.getText();
	IPath path= Path.fromOSString(comboText);

	if (path.segmentCount() > 0 && ensureTargetFileIsValid(path.toFile()) && path.getFileExtension() == null)
		// append .jar
		path= path.addFileExtension(JarPackagerUtil.JAR_EXTENSION);

	fJarPackage.setJarLocation(path);
}
 
Example 13
Source File: FatJarPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Stores the widget values in the JAR package.
 */
@Override
protected void updateModel() {
	super.updateModel();

	String comboText= fAntScriptNamesCombo.getText();
	IPath path= Path.fromOSString(comboText);
	if (path.segmentCount() > 0 && ensureAntScriptFileIsValid(path.toFile()) && path.getFileExtension() == null)
		path= path.addFileExtension(ANTSCRIPT_EXTENSION);

	fAntScriptLocation= getAbsoluteLocation(path);
}
 
Example 14
Source File: FixedFatJarExportPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**
 * Stores the widget values in the JAR package.
 */
@Override
protected void updateModel() {
	super.updateModel();

	String comboText= fAntScriptNamesCombo.getText();
	IPath path= Path.fromOSString(comboText);
	if (path.segmentCount() > 0 && ensureAntScriptFileIsValid(path.toFile()) && path.getFileExtension() == null)
		path= path.addFileExtension(ANTSCRIPT_EXTENSION);

	fAntScriptLocation= getAbsoluteLocation(path);
}
 
Example 15
Source File: FileReportProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Copys old report config file to new report config file.
 * 
 * @param newReportPath
 *            the new report path.
 * @param oldReportPath
 *            the old report path.
 * @throws IOException
 *             if an error occurs.
 */
public static void copyReportConfigFile( IPath newReportPath,
		IPath oldReportPath ) throws IOException
{
	if ( oldReportPath != null )
	{
		String retConfigExtension = "rptconfig"; //$NON-NLS-1$
		IPath newConfigPath = newReportPath.removeFileExtension( );
		IPath oldConfigPath = oldReportPath.removeFileExtension( );

		newConfigPath = newConfigPath.addFileExtension( retConfigExtension );
		oldConfigPath = oldConfigPath.addFileExtension( retConfigExtension );

		File newConfigFile = newConfigPath.toFile( );
		File oldConfigFile = oldConfigPath.toFile( );

		if ( oldConfigFile.exists( ) )
		{
			copyFile( oldConfigFile, newConfigFile );
		}
		else
		{
			if ( newConfigFile.exists( ) )
			{
				if ( !newConfigFile.delete( ) )
				{
					throw new IOException( Messages.getFormattedString( "FileReportProvider.CopyConfigFile.DeleteFailure", //$NON-NLS-1$
							new Object[]{
								newConfigFile.getAbsolutePath( )
							} ) );
				}
			}
		}
	}
}
 
Example 16
Source File: AbstractRequireResolver.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
protected IPath loadAsDirectory(IPath x, String... extensions)
{
	File packageJSON = x.append(PACKAGE_JSON).toFile();
	if (packageJSON.isFile())
	{
		try
		{
			IFileStore fileStore = EFS.getStore(packageJSON.toURI());
			String rawJSON = IOUtil.read(fileStore.openInputStream(EFS.NONE, new NullProgressMonitor()));
			@SuppressWarnings("rawtypes")
			Map json = (Map) JSON.parse(rawJSON);
			String mainFile = (String) json.get(MAIN);
			if (!StringUtil.isEmpty(mainFile))
			{
				// package.json may not have a 'main' property set
				IPath m = x.append(mainFile);
				IPath result = loadAsFile(m);
				if (result != null)
				{
					return result;
				}
			}
		}
		catch (CoreException e)
		{
			IdeLog.log(JSCorePlugin.getDefault(), e.getStatus());
		}
	}

	// If package.json doesn't point to a main file, fall back to index.js
	List<String> ext = CollectionsUtil.newList(extensions);
	ext.add(0, JS);

	IPath index = x.append(INDEX);
	for (String extension : ext)
	{
		IPath potential = index.addFileExtension(extension);
		if (potential.toFile().isFile())
		{
			return potential;
		}
	}
	return null;
}
 
Example 17
Source File: SaveAsDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void okPressed( )
{
	// Get new path.
	IPath path = support.getFileLocationFullPath( )
			.append( support.getFileName( ) );

	// If the user does not supply a file extension and the save
	// as dialog was provided a default file name, then append the extension
	// of the default filename to the new name
	if ( !ReportPlugin.getDefault( )
			.isReportDesignFile( path.toOSString( ) ) )
	{
		String[] parts = support.getInitialFileName( ).split( "\\." ); //$NON-NLS-1$
		path = path.addFileExtension( parts[parts.length - 1] );
	}

	// If the path already exists then confirm overwrite.
	File file = path.toFile( );
	if ( file.exists( ) )
	{
		String[] buttons = new String[]{
				IDialogConstants.YES_LABEL,
				IDialogConstants.NO_LABEL,
				IDialogConstants.CANCEL_LABEL
		};

		String question = Messages.getFormattedString( "SaveAsDialog.overwriteQuestion", //$NON-NLS-1$
				new Object[]{
					path.toOSString( )
				} );
		MessageDialog d = new MessageDialog( getShell( ),
				Messages.getString( "SaveAsDialog.Question" ), //$NON-NLS-1$
				null,
				question,
				MessageDialog.QUESTION,
				buttons,
				0 );
		int overwrite = d.open( );
		switch ( overwrite )
		{
			case 0 : // Yes
				break;
			case 1 : // No
				return;
			case 2 : // Cancel
			default :
				cancelPressed( );
				return;
		}
	}

	// Store path and close.
	result = path;
	close( );
}
 
Example 18
Source File: WizardSaveAsPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public IPath getResult( )
{

	IPath path = support.getFileLocationFullPath( )
			.append( support.getFileName( ) );

	// If the user does not supply a file extension and if the save
	// as dialog was provided a default file name append the extension
	// of the default filename to the new name
	if ( ReportPlugin.getDefault( )
			.isReportDesignFile( support.getInitialFileName( ) )
			&& !ReportPlugin.getDefault( )
					.isReportDesignFile( path.toOSString( ) ) )
	{
		String[] parts = support.getInitialFileName( ).split( "\\." ); //$NON-NLS-1$
		path = path.addFileExtension( parts[parts.length - 1] );
	}
	else if ( support.getInitialFileName( )
			.endsWith( IReportEditorContants.TEMPLATE_FILE_EXTENTION )
			&& !path.toOSString( )
					.endsWith( IReportEditorContants.TEMPLATE_FILE_EXTENTION ) )
	{
		path = path.addFileExtension( "rpttemplate" ); //$NON-NLS-1$
	}
	// If the path already exists then confirm overwrite.
	File file = path.toFile( );
	if ( file.exists( ) )
	{
		String[] buttons = new String[]{
				IDialogConstants.YES_LABEL,
				IDialogConstants.NO_LABEL,
				IDialogConstants.CANCEL_LABEL
		};

		String question = Messages.getFormattedString( "SaveAsDialog.overwriteQuestion", //$NON-NLS-1$
				new Object[]{
					path.toOSString( )
				} );
		MessageDialog d = new MessageDialog( getShell( ),
				Messages.getString( "SaveAsDialog.Question" ), //$NON-NLS-1$
				null,
				question,
				MessageDialog.QUESTION,
				buttons,
				0 );
		int overwrite = d.open( );
		switch ( overwrite )
		{
			case 0 : // Yes
				break;
			case 1 : // No
				return null;
			case 2 : // Cancel
			default :
				return Path.EMPTY;
		}
	}

	return path;
}
 
Example 19
Source File: WizardSaveAsPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Get the saving path
 * 
 * @return the saving path
 */
public IPath getResult( )
{

	IPath path = resourceGroup.getContainerFullPath( )
			.append( resourceGroup.getResource( ) );

	// If the user does not supply a file extension and if the save
	// as dialog was provided a default file name append the extension
	// of the default filename to the new name
	if ( path.getFileExtension( ) == null )
	{
		if ( originalFile != null
				&& originalFile.getFileExtension( ) != null )
			path = path.addFileExtension( originalFile.getFileExtension( ) );
		else if ( originalName != null )
		{
			int pos = originalName.lastIndexOf( '.' );
			if ( ++pos > 0 && pos < originalName.length( ) )
				path = path.addFileExtension( originalName.substring( pos ) );
		}
	}

	// If the path already exists then confirm overwrite.
	IFile file = ResourcesPlugin.getWorkspace( ).getRoot( ).getFile( path );

	if ( file.exists( ) )
	{
		String[] buttons = new String[]{
				IDialogConstants.YES_LABEL,
				IDialogConstants.NO_LABEL,
				IDialogConstants.CANCEL_LABEL
		};
		String question = Messages.getFormattedString( "WizardSaveAsPage.OverwriteQuestion", //$NON-NLS-1$
				new Object[]{
					path.toOSString( )
				} );
		MessageDialog d = new MessageDialog( getShell( ),
				Messages.getString( "WizardSaveAsPage.Question" ), //$NON-NLS-1$
				null,
				question,
				MessageDialog.QUESTION,
				buttons,
				0 );
		int overwrite = d.open( );
		switch ( overwrite )
		{
			case 0 : // Yes
				break;
			case 1 : // No
				return null;
			case 2 : // Cancel
			default :
				return Path.EMPTY;
		}
	}

	return path;
}
 
Example 20
Source File: NewEditorHelper.java    From depan with Apache License 2.0 3 votes vote down vote up
/**
 * Ensure that we have a file extension on the file name.  This does not
 * overwrite an existing extension, but ensures that at least one extension
 * is present.
 * 
 * @param savePath Initial save path from user
 * @param defExt default extension to add if {@code savePath} lacks one
 * @return valid IFile with an extension.
 */
public static IFile buildNameWithExtension(IPath savePath, String defExt) {
  if (null == savePath.getFileExtension()) {
    savePath.addFileExtension(defExt);
  }
  return ResourcesPlugin.getWorkspace().getRoot().getFile(savePath);
}