本文整理匯總了Java中org.eclipse.core.resources.IFile.create方法的典型用法代碼示例。如果您正苦於以下問題:Java IFile.create方法的具體用法?Java IFile.create怎麽用?Java IFile.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.core.resources.IFile
的用法示例。
在下文中一共展示了IFile.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createTestProject
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/**
* Creates a project with two files.
*/
@SuppressWarnings("resource")
@BeforeClass
public static void createTestProject() throws Exception {
staticProject = ProjectUtils.createJSProject(PROJECT_NAME);
IFolder path = staticProject.getFolder("src").getFolder("path");
path.create(true, true, null);
IFile libFile = path.getFile("Libs.n4js");
libFile.create(new StringInputStream(
"export public class MyFirstClass {} export public class MySecondClass {} class MyHiddenClass {}",
libFile.getCharset()), true, monitor());
IFile moreLibFile = path.getFile("MoreLibs.n4js");
moreLibFile.create(new StringInputStream(
"export public class MoreLibFirstClass {} export public class MoreLibSecondClass {}",
moreLibFile.getCharset()), true, monitor());
IFile testFile = path.getFile("Test.n4js");
testFile.create(new StringInputStream("", testFile.getCharset()), true, monitor());
addNature(staticProject, XtextProjectHelper.NATURE_ID);
ProjectUtils.waitForAutoBuild();
}
示例2: createServiceClass
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public static void createServiceClass(IFile classFile, String packageName,
String className, String languageName, String layerName,
IProgressMonitor monitor) throws IOException, CoreException {
String content = getContent(AddDebugLayerHandler.class.getClassLoader()
.getResourceAsStream(DEBUG_SERVICE_TEMPLATE_PATH), "UTF8");
content = content.replaceFirst(PACKAGE_TAG, packageName);
content = content.replaceFirst(CLASS_NAME_TAG, className);
content = content.replaceFirst(LANGUAGE_NAME_TAG, languageName);
content = content.replaceFirst(LAYER_NAME_TAG, layerName);
classFile.create(
new ByteArrayInputStream(content.getBytes(Charset
.forName("UTF8"))), true, monitor);
}
示例3: createSchema
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
static IFolder createSchema(String name, boolean open, IProject project) throws CoreException {
IFolder projectFolder = project.getFolder(DbObjType.SCHEMA.name());
if (!projectFolder.exists()) {
projectFolder.create(false, true, null);
}
IFolder schemaFolder = projectFolder.getFolder(name);
if (!schemaFolder.exists()) {
schemaFolder.create(false, true, null);
}
IFile file = projectFolder.getFile(name + POSTFIX);
if (!file.exists()) {
StringBuilder sb = new StringBuilder();
sb.append(MessageFormat.format(PATTERN, DbObjType.SCHEMA, name));
sb.append(MessageFormat.format(OWNER_TO, DbObjType.SCHEMA, name));
file.create(new ByteArrayInputStream(sb.toString().getBytes()), false, null);
}
if (open) {
openFileInEditor(file);
}
return schemaFolder;
}
示例4: writePluginJpf
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
@SuppressWarnings("nls")
private void writePluginJpf(IProgressMonitor monitor, IProject project) throws CoreException
{
Document doc = new Document();
doc.setDocType(new DocType("plugin", "-//JPF//Java Plug-in Manifest 1.0",
"http://jpf.sourceforge.net/plugin_1_0.dtd"));
Element rootElem = new Element("plugin");
doc.setRootElement(rootElem);
rootElem.setAttribute("id", project.getName());
rootElem.setAttribute("version", "1");
Element requires = new Element("requires");
rootElem.addContent(requires);
Element runtime = new Element("runtime");
Element srcLib = new Element("library");
srcLib.setAttribute("type", "code");
srcLib.setAttribute("path", "classes/");
srcLib.setAttribute("id", "classes");
Element export = new Element("export");
export.setAttribute("prefix", "*");
srcLib.addContent(export);
runtime.addContent(srcLib);
rootElem.addContent(runtime);
fFirstPage.customizeManifest(rootElem, project, monitor);
if( requires.getContentSize() == 0 )
{
rootElem.removeContent(requires);
}
IFile manifest = JPFProject.getManifest(project);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
xmlOut.output(doc, baos);
}
catch( IOException e )
{
throw new RuntimeException(e);
}
manifest.create(new ByteArrayInputStream(baos.toByteArray()), true, monitor);
}
示例5: createFileDeleteIfExists
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/**
* Create a file in a folder with the specified name and content
*
* @param fullpath
* @param filename
* @param content
* @throws CoreException
* @throws InterruptedException
*/
public static IFile createFileDeleteIfExists(String fullpath, String filename, String content,
IProgressMonitor monitor) throws CoreException, InterruptedException {
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
subMonitor.setTaskName("Create file delete if it exists " + fullpath);
IFile newFile;
try {
IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
IContainer container = (IContainer) wroot.findMember(new Path(fullpath));
newFile = container.getFile(new Path(filename));
if (newFile.exists()) {
JDTManager.rename(newFile, new NullProgressMonitor());
newFile.delete(true, new NullProgressMonitor());
}
subMonitor.split(30);
byte[] source = content.getBytes(Charset.forName("UTF-8"));
newFile.create(new ByteArrayInputStream(source), true, new NullProgressMonitor());
subMonitor.split(70);
} finally {
subMonitor.done();
}
return newFile;
}
示例6: createSubjobInSpecifiedFolder
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/**
* @param subJobXMLPath
* @param parameterFilePath
* @param parameterFile
* @param subJobFile
* @param importFromPath
* @param subjobPath
* @return
* @throws InstantiationException
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws NoSuchMethodException
* @throws JAXBException
* @throws ParserConfigurationException
* @throws SAXException
* @throws IOException
* @throws CoreException
* @throws FileNotFoundException
*/
public static Container createSubjobInSpecifiedFolder(IPath subJobXMLPath, IPath parameterFilePath, IFile parameterFile,
IFile subJobFile, IPath importFromPath,String subjobPath) throws InstantiationException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException, JAXBException, ParserConfigurationException,
SAXException, IOException, CoreException, FileNotFoundException {
UiConverterUtil converterUtil = new UiConverterUtil();
Object[] subJobContainerArray=null;
IFile xmlFile = ResourcesPlugin.getWorkspace().getRoot().getFile(subJobXMLPath);
File file = new File(xmlFile.getFullPath().toString());
if (file.exists()) {
subJobContainerArray = converterUtil.convertToUiXml(importFromPath.toFile(), subJobFile, parameterFile,true);
} else {
IProject iProject = ResourcesPlugin.getWorkspace().getRoot().getProject(parameterFilePath.segment(1));
IFolder iFolder = iProject.getFolder(subjobPath.substring(0, subjobPath.lastIndexOf('/')));
if (!iFolder.exists()) {
iFolder.create(true, true, new NullProgressMonitor());
}
IFile subjobXmlFile = iProject.getFile(subjobPath);
subJobContainerArray = converterUtil.convertToUiXml(importFromPath.toFile(), subJobFile, parameterFile,true);
if (!subjobXmlFile.exists() && subJobContainerArray[1] == null) {
subjobXmlFile.create(new FileInputStream(importFromPath.toString()), true, new NullProgressMonitor());
}
}
return (Container) subJobContainerArray[0];
}
示例7: generateReport
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public static void generateReport(final DesignModel model, final IFile output, final IProgressMonitor monitor) {
try {
final ByteArrayOutputStream data = new ByteArrayOutputStream();
final OutputStreamWriter writer = new OutputStreamWriter(data);
generateReport(model, writer);
writer.close();
final ByteArrayInputStream source = new ByteArrayInputStream(data.toByteArray());
if (output.exists()) {
output.setContents(source, true, true, monitor);
} else {
output.create(source, true, monitor);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例8: getBuildPoliciesForGraph
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public static IFile getBuildPoliciesForGraph(IFile file, boolean create)
throws CoreException, FileNotFoundException {
String name = PreferenceManager.getBuildPoliciesFileName(file.getProject().getName());
IFolder folder = (IFolder) file.getParent();
IFile policiesFile = folder.getFile(name);
if (policiesFile == null || !policiesFile.exists()) {
if (create) {
byte[] bytes = getDefaultBuildFileComment().getBytes();
InputStream source = new ByteArrayInputStream(bytes);
policiesFile.create(source, IResource.NONE, null);
policiesFile.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} else {
throw new FileNotFoundException(folder.getFullPath().append(name).toString());
}
}
return policiesFile;
}
示例9: doCreateTestFile
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/***/
@SuppressWarnings("resource")
protected IFile doCreateTestFile(IFolder folder, String fullName, CharSequence content) throws CoreException {
IFile file = folder.getFile(fullName);
file.create(new StringInputStream(content.toString()), true, monitor());
waitForAutoBuild();
return file;
}
示例10: createArchive
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
private void createArchive(String projectName) throws CoreException, IOException {
IProject project = workspace.getProject(projectName);
IFolder libFolder = project.getFolder(LIB_FOLDER_NAME);
libFolder.create(false, true, null);
IFile archiveFile = libFolder.getFile(host.archiveProjectId + ".nfar");
ByteArrayOutputStream byteArrayOutputSteam = new ByteArrayOutputStream();
final ZipOutputStream zipOutputStream = new ZipOutputStream(byteArrayOutputSteam);
zipOutputStream.putNextEntry(new ZipEntry("src/A.js"));
zipOutputStream.putNextEntry(new ZipEntry("src/B.js"));
zipOutputStream.putNextEntry(new ZipEntry("src/sub/B.js"));
zipOutputStream.putNextEntry(new ZipEntry("src/sub/C.js"));
zipOutputStream.putNextEntry(new ZipEntry("src/sub/leaf/D.js"));
zipOutputStream.putNextEntry(new ZipEntry(IN4JSProject.N4MF_MANIFEST));
// this will close the stream
CharStreams.write("ProjectId: " + host.archiveProjectId + "\n" +
"ProjectType: library\n" +
"ProjectVersion: 0.0.1-SNAPSHOT\n" +
"VendorId: org.eclipse.n4js\n" +
"VendorName: \"Eclipse N4JS Project\"\n" +
"Libraries { \"" + LIB_FOLDER_NAME + "\"\n }\n" +
"Output: \"src-gen\"" +
"Sources {\n" +
" source { " +
" \"src\"\n" +
" }\n" +
"}\n", CharStreams.newWriterSupplier(new OutputSupplier<ZipOutputStream>() {
@Override
public ZipOutputStream getOutput() throws IOException {
return zipOutputStream;
}
}, Charsets.UTF_8));
archiveFile.create(new ByteArrayInputStream(byteArrayOutputSteam.toByteArray()), false, null);
host.setArchiveFileURI(URI.createPlatformResourceURI(archiveFile.getFullPath().toString(), true));
}
示例11: doSaveAsSubJob
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/**
* Do save as sub graph.
*
* @param file
* the file
* @param container
* the container
* @return the i file
*/
public IFile doSaveAsSubJob(IFile file, Container container) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
ConverterUtil.INSTANCE.convertToXML(container, false, null, null);
if (file != null) {
CanvasUtils.INSTANCE.fromObjectToXML(container,out);
file.create(new ByteArrayInputStream(out.toByteArray()), true, null);
getCurrentEditor().genrateTargetXml(file, null, container);
getCurrentEditor().setDirty(false);
}
} catch (Exception e ) {
MessageDialog.openError(new Shell(), "Error", "Exception occured while saving the graph -\n" + e.getMessage());
}
finally {
try {
out.close();
} catch (IOException ioException) {
logger.warn("Exception occurred while closing stream");
}
}
return file;
}
示例12: writeInFile
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public static void writeInFile(IFile file, String contents, IProgressMonitor monitor) throws CoreException, IOException{
InputStream stream = new ByteArrayInputStream(contents.getBytes(("UTF-8")));
if (file.exists()) {
file.setContents(stream, true, true, monitor);
} else {
if(file.getParent() instanceof IFolder && !file.getParent().exists()){
IFolderUtils.create((IFolder) file.getParent(), true, true, monitor);
}
file.create(stream, true, monitor);
}
stream.close();
}
示例13: create
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public static void create(IProject project, String groupId, String version, String artifactId, String name, String gwversion) throws IOException, CoreException {
String newline = System.getProperty("line.separator");
URL url = IOHelper.class.getResource("pom.xml");
InputStream input = url.openStream();
StringBuffer sb = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line).append(newline);
}
String data = String.format(sb.toString(), groupId, version, artifactId, name, gwversion);
IFile pom = project.getFile("pom.xml");
pom.create(new ByteArrayInputStream(data.getBytes()), true, new NullProgressMonitor());
}
示例14: createProject
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/**
* This method creates a new java project based on the user inputs, captured in WizardInput object.
* The new project is created in the current workspace.
* @param wizardInput
* @return IJavaProject
* @throws CoreException
* @throws IOException
**/
public IJavaProject createProject(WizardInput wizardInput) throws CoreException, IOException
{
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(wizardInput.getProjectName());
project.create(null);
project.open(null);
IProjectDescription description = project.getDescription();
description.setNatureIds(new String[] { JavaCore.NATURE_ID });
project.setDescription(description, null);
IJavaProject javaProject = JavaCore.create(project);
IFolder binFolder = project.getFolder("bin");
binFolder.create(false, true, null);
javaProject.setOutputLocation(binFolder.getFullPath(), null);
List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
for (LibraryLocation element : locations) {
entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null));
}
InputStream is = new BufferedInputStream(new FileInputStream(wizardInput.getSootPath().toOSString()));
IFile jarFile = project.getFile("soot-trunk.jar");
jarFile.create(is, false, null);
IPath path = jarFile.getFullPath();
entries.add(JavaCore.newLibraryEntry(path, null, null));
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
IFolder sourceFolder = project.getFolder("src");
sourceFolder.create(false, true, null);
IPackageFragmentRoot root1 = javaProject.getPackageFragmentRoot(sourceFolder);
IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
newEntries[oldEntries.length] = JavaCore.newSourceEntry(root1.getPath());
javaProject.setRawClasspath(newEntries, null);
String filepath = sourceFolder.getLocation().toOSString();
File file = new File(filepath);
wizardInput.setFile(file);
try {
CodeGenerator.generateSource(wizardInput);
} catch (JClassAlreadyExistsException e) {
e.printStackTrace();
}
sourceFolder.refreshLocal(1, null);
javaProject.open(null);
return javaProject;
}
示例15: createExample
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
protected void createExample(IProject project) {
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
try (InputStream stream = FileLocator.openStream(bundle, new Path("examples/greeter.sol"), false)) {
IFile file = project.getFile("greeter.sol");
file.create(stream, true, null);
} catch (Exception e) {
e.printStackTrace();
}
}