Java Code Examples for org.eclipse.core.resources.IFolder#getFile()

The following examples show how to use org.eclipse.core.resources.IFolder#getFile() . 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: ImportConnectorArchiveOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void importIcons(final File tmpDir) {
    final File[] files = tmpDir.listFiles(imageFileFilter);
    if (files != null) {
        final IRepositoryStore defStore = getDefinitionStore();
        for (final File iconFile : files) {
            final IFolder folder = defStore.getResource();
            final IFile file = folder.getFile(iconFile.getName());
            try {
                if (file.exists() && FileActionDialog.confirmDeletionQuestion(iconFile.getName())) {
                    file.delete(true, Repository.NULL_PROGRESS_MONITOR);
                }
                file.create(new FileInputStream(iconFile), true, Repository.NULL_PROGRESS_MONITOR);
            } catch (final Exception e) {
                BonitaStudioLog.error(e);
            }
        }
    }
}
 
Example 2
Source File: BuilderParticipantTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultConfiguration() throws Exception {
	IJavaProject project = createJavaProject("foo");
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IFolder folder = project.getProject().getFolder("src");
	IFile file = folder.getFile("Foo" + F_EXT);
	file.create(new StringInputStream("object Foo"), true, monitor());
	build();
	IFile generatedFile = project.getProject().getFile("./src-gen/Foo.txt");
	assertTrue(generatedFile.exists());
	assertTrue(generatedFile.isDerived());
	assertTrue(generatedFile.findMarkers(DerivedResourceMarkers.MARKER_ID, false, IResource.DEPTH_ZERO).length == 1);
	assertEquals("object Foo", readFile(generatedFile).trim());
	file.setContents(new StringInputStream("object Bar"), true, true, monitor());
	build();
	assertFalse(generatedFile.exists());
	generatedFile = project.getProject().getFile("./src-gen/Bar.txt");
	assertTrue(generatedFile.exists());
	assertTrue(generatedFile.isDerived());
	assertTrue(generatedFile.findMarkers(DerivedResourceMarkers.MARKER_ID, false, IResource.DEPTH_ZERO).length == 1);
	assertEquals("object Bar", readFile(generatedFile).trim());
	file.delete(true, monitor());
	build();
	assertFalse(generatedFile.exists());
}
 
Example 3
Source File: IntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testCleanBuild() throws Exception {
	IJavaProject project = createJavaProject("foo");
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IFolder folder = project.getProject().getFolder("src");
	IFile file = folder.getFile("Foo" + F_EXT);
	file.create(new StringInputStream("object Foo"), true, monitor());
	build();
	assertTrue(indexContainsElement(file.getFullPath().toString(), "Foo"));
	assertEquals(1, countResourcesInIndex());

	getBuilderState().addListener(this);
	project.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, monitor());
	build();
	// clean build should first remove the IResourceDescriptor and then add it again  
	assertEquals(2, getEvents().size());
	assertEquals(1, getEvents().get(0).getDeltas().size());
	assertNotNull(getEvents().get(0).getDeltas().get(0).getOld());
	assertNull(getEvents().get(0).getDeltas().get(0).getNew());
	assertEquals(1, getEvents().get(1).getDeltas().size());
	assertNull(getEvents().get(1).getDeltas().get(0).getOld());
	assertNotNull(getEvents().get(1).getDeltas().get(0).getNew());
}
 
Example 4
Source File: BuilderParticipantTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNoOutputFolderCreation() throws Exception {
	OutputConfigurationProvider outputConfigurationProvider = new OutputConfigurationProvider() {
		@Override
		public Set<OutputConfiguration> getOutputConfigurations() {
			final Set<OutputConfiguration> result = super.getOutputConfigurations();
			OutputConfiguration configuration = result.iterator().next();
			configuration.setCreateOutputDirectory(false);
			return result;
		}
	};
	BuilderPreferenceAccess.Initializer initializer = new BuilderPreferenceAccess.Initializer();
	initializer.setOutputConfigurationProvider(outputConfigurationProvider);
	initializer.initialize(preferenceStoreAccess);

	IJavaProject project = createJavaProject("foo");
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IFolder folder = project.getProject().getFolder("src");
	IFile file = folder.getFile("Foo" + F_EXT);
	file.create(new StringInputStream("object Foo"), true, monitor());
	build();
	final IFile generatedFile = project.getProject().getFile("./src-gen/Foo.txt");
	assertFalse(generatedFile.exists());
}
 
Example 5
Source File: BuilderParticipantTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testGenerateIntoProjectOutputDirectory() throws Exception {
	IJavaProject project = createJavaProject("testGenerateIntoProjectOutputDirectory");
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	preferenceStoreAccess.getWritablePreferenceStore(project.getProject()).setValue(getDefaultOutputDirectoryKey(),
			"./");
	IFolder folder = project.getProject().getFolder("src");
	IFile file = folder.getFile("Foo" + F_EXT);
	file.create(new StringInputStream("object Foo"), true, monitor());
	build();
	IFile generatedFile = project.getProject().getFile("./Foo.txt");
	assertTrue(generatedFile.exists());
	preferenceStoreAccess.getWritablePreferenceStore(project.getProject()).setValue(getDefaultOutputDirectoryKey(),
			".");
	file = folder.getFile("Bar" + F_EXT);
	file.create(new StringInputStream("object Bar"), true, monitor());
	build();
	generatedFile = project.getProject().getFile("./Bar.txt");
	assertTrue(generatedFile.exists());
}
 
Example 6
Source File: EclipseResourceFileSystemAccess2Test.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testWriteReadFiles() throws Exception {
	fsa.generateFile("tmp/X", "XX");
	IFolder dir = project.getFolder("src-gen/tmp");
	assertTrue(dir.exists());
	IFile file = dir.getFile("X");
	assertTrue(file.exists());
	assertEquals("XX", fsa.readTextFile("tmp/X"));

	fsa.generateFile("tmp/Y", "\1\2\3");
	InputStream stream = fsa.readBinaryFile("tmp/Y");
	try {
		assertEquals("\1\2\3", new String(ByteStreams.toByteArray(stream)));
	} finally {
		stream.close();
	}
}
 
Example 7
Source File: IntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testDeleteFile() throws Exception {
	IJavaProject project = createJavaProject("foo");
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IFolder folder = project.getProject().getFolder("src");
	IFile file = folder.getFile("Foo" + F_EXT);
	file.create(new StringInputStream("object Foo"), true, monitor());
	build();
	assertTrue(indexContainsElement(file.getFullPath().toString(), "Foo"));
	assertEquals(1, countResourcesInIndex());

	getBuilderState().addListener(this);
	file.delete(true, monitor());
	build();
	assertEquals(1, getEvents().get(0).getDeltas().size());
	assertNull(getEvents().get(0).getDeltas().get(0).getNew());
	assertEquals(0, countResourcesInIndex());
}
 
Example 8
Source File: TracePackageExportOperation.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates a linked resource in the specified folder
 *
 * @param exportFolder the folder that will contain the linked resource
 * @param res the resource to export
 * @throws CoreException when createLink fails
 * @return the created linked resource
 */
private static IResource createExportResource(IFolder exportFolder, IResource res) throws CoreException {
    IResource ret = null;
    // Note: The resources cannot be HIDDEN or else they are ignored by ArchiveFileExportOperation
    if (res instanceof IFolder) {
        IFolder folder = exportFolder.getFolder(res.getName());
        folder.createLink(res.getLocationURI(), IResource.REPLACE, null);
        ret = folder;
    } else if (res instanceof IFile) {
        IFile file = exportFolder.getFile(res.getName());
        if (!file.exists()) {
            file.createLink(res.getLocationURI(), IResource.NONE, null);
        }
        ret = file;
    }
    return ret;
}
 
Example 9
Source File: XtextBuilderParticipantTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testParticipantInvoked() throws Exception {
	startLogging();
	IJavaProject project = createJavaProject("foo");
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IFolder folder = project.getProject().getFolder("src");
	IFile file = folder.getFile("Foo" + F_EXT);
	file.create(new StringInputStream("object Foo"), true, monitor());
	build();
	assertTrue(0 < getInvocationCount());
	validateContexts();
	reset();
	
	file.delete(true, monitor());
	build();
	assertEquals(1, getInvocationCount());
	assertSame(BuildType.INCREMENTAL, getContext().getBuildType());
	validateContexts();
	reset();
	
	project.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, monitor());
	assertSame(BuildType.CLEAN, getContext().getBuildType());
	build();
	assertEquals(1, getInvocationCount());
	assertSame(BuildType.CLEAN, getContext().getBuildType());
	validateContexts();
	reset();
	
	project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor());
	assertEquals(0, getInvocationCount());
	validateContexts();
	reset();
}
 
Example 10
Source File: WebProjectUtil.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Attempt to resolve the given file within the project's {@code WEB-INF}. Note that this method
 * may return a file that is in a build location (e.g.,
 * {@code target/m2e-wtp/web-resources/WEB-INF}) which may be frequently removed or regenerated.
 *
 * @return the file location or {@code null} if not found
 */
public static IFile findInWebInf(IProject project, IPath filePath) {
  // Try to obtain the directory as if it was a Dynamic Web Project
  IVirtualComponent component = ComponentCore.createComponent(project);
  if (component != null && component.exists()) {
    IVirtualFolder root = component.getRootFolder();
    // the root should exist, but the WEB-INF may not yet exist
    IVirtualFile file = root.getFolder(WEB_INF).getFile(filePath);
    if (file != null && file.exists()) {
      return file.getUnderlyingFile();
    }
    return null;
  }
  // Otherwise check the standard places
  for (String possibleWebInfContainer : DEFAULT_WEB_PATHS) {
    // check each directory component to simplify mocking in tests
    // so we can just say WEB-INF doesn't exist
    IFolder defaultLocation = project.getFolder(possibleWebInfContainer);
    if (defaultLocation != null && defaultLocation.exists()) {
      defaultLocation = defaultLocation.getFolder(WEB_INF);
      if (defaultLocation != null && defaultLocation.exists()) {
        IFile resourceFile = defaultLocation.getFile(filePath);
        if (resourceFile != null && resourceFile.exists()) {
          return resourceFile;
        }
      }
    }
  }
  return null;
}
 
Example 11
Source File: CodeTemplatesTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private void validateNonConfigFiles(IFile mostImportant,
    String webXmlNamespace, String webXmlSchemaUrl, String servletVersion)
    throws ParserConfigurationException, SAXException, IOException, CoreException {
  IFolder src = project.getFolder("src");
  IFolder main = src.getFolder("main");
  IFolder java = main.getFolder("java");
  IFile servlet = java.getFile("HelloAppEngine.java");
  Assert.assertTrue(servlet.exists());
  Assert.assertEquals(servlet, mostImportant);

  IFolder webapp = main.getFolder("webapp");
  IFolder webinf = webapp.getFolder("WEB-INF");
  IFile webXml = webinf.getFile("web.xml");
  Element root = buildDocument(webXml).getDocumentElement();
  Assert.assertEquals("web-app", root.getNodeName());
  Assert.assertEquals(webXmlNamespace, root.getNamespaceURI());
  Assert.assertEquals(webXmlNamespace + " " + webXmlSchemaUrl,
      root.getAttribute("xsi:schemaLocation"));
  Assert.assertEquals(servletVersion, root.getAttribute("version"));
  Element servletClass = (Element) root
      .getElementsByTagNameNS("http://java.sun.com/xml/ns/javaee", "servlet-class").item(0);
  if (servletClass != null) { // servlet 2.5
    Assert.assertEquals("HelloAppEngine", servletClass.getTextContent());
  }
  
  IFile htmlFile = webapp.getFile("index.html");
  Element html = buildDocument(htmlFile).getDocumentElement();
  Assert.assertEquals("html", html.getNodeName());

  IFolder test = src.getFolder("test");
  IFolder testJava = test.getFolder("java");
  IFile servletTest = testJava.getFile("HelloAppEngineTest.java");
  Assert.assertTrue(servletTest.exists());
  IFile mockServletResponse = testJava.getFile("MockHttpServletResponse.java");
  Assert.assertTrue(mockServletResponse.exists());
}
 
Example 12
Source File: CodeTemplatesTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private void validateAppYaml() throws IOException, CoreException {
  IFolder appengineFolder = project.getFolder("src/main/appengine");
  Assert.assertTrue(appengineFolder.exists());
  IFile appYaml = appengineFolder.getFile("app.yaml");
  Assert.assertTrue(appYaml.exists());

  try (BufferedReader reader = new BufferedReader(
      new InputStreamReader(appYaml.getContents(), StandardCharsets.UTF_8))) {
    Assert.assertEquals("runtime: java", reader.readLine());
    Assert.assertEquals("env: flex", reader.readLine());
  }
}
 
Example 13
Source File: LibraryClasspathContainerSerializer.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private IFile getFile(IJavaProject javaProject, String id, boolean create)
    throws CoreException {
  IFolder settingsFolder = javaProject.getProject().getFolder(".settings"); //$NON-NLS-1$
  IFolder folder =
      settingsFolder.getFolder(FrameworkUtil.getBundle(getClass()).getSymbolicName());
  if (!folder.exists() && create) {
    ResourceUtils.createFolders(folder, null);
  }
  IFile containerFile = folder.getFile(id + ".container"); //$NON-NLS-1$
  return containerFile;
}
 
Example 14
Source File: WorkspaceModelsManager.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
IFile createUnclassifiedModelsProjectAndAdd(final IPath location) {
	IFile iFile = null;
	try {
		final IFolder modelFolder = createUnclassifiedModelsProject(location);
		iFile = modelFolder.getFile(location.lastSegment());
		if ( iFile.exists() ) {
			if ( iFile.isLinked() ) {
				final IPath path = iFile.getLocation();
				if ( path.equals(location) ) {
					// First case, this is a linked resource to the same location. In that case, we simply return
					// its name.
					return iFile;
				} else {
					// Second case, this resource is a link to another location. We create a filename that is
					// guaranteed not to exist and change iFile accordingly.
					iFile = createUniqueFileFrom(iFile, modelFolder);
				}
			} else {
				// Third case, this resource is local and we do not want to overwrite it. We create a filename that
				// is guaranteed not to exist and change iFile accordingly.
				iFile = createUniqueFileFrom(iFile, modelFolder);
			}
		}
		iFile.createLink(location, IResource.NONE, null);
		// RefreshHandler.run();
		return iFile;
	} catch (final CoreException e) {
		e.printStackTrace();
		MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Error in creation",
			"The file " + (iFile == null ? location.lastSegment() : iFile.getFullPath().lastSegment()) +
				" cannot be created because of the following exception " + e.getMessage());
		return null;
	}
}
 
Example 15
Source File: HybridProjectTest.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private void checkDerivedSubFolders(HybridProject hProject, String folderName) {
	IFolder folder = hProject.getProject().getFolder(folderName);
	IFolder subFolder1 = folder.getFolder(folder.getName() + "0");
	assertTrue(subFolder1.isDerived());
	IFolder subFolder2 = folder.getFolder(folder.getName() + "1");
	assertTrue(subFolder2.isDerived());

	IFile subFile1 = folder.getFile("file0");
	assertFalse(subFile1.isDerived());

	IFile subFile2 = folder.getFile("file1");
	assertFalse(subFile2.isDerived());
}
 
Example 16
Source File: BuilderParticipantPluginUITest.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 *
 * 01. Class0 uses Class1 in require statement and in isa function
 * 02. Class1 file is renamed
 * 05. Class0 should get error marker at require statement and at isa function
 * 06. Class1 is renamed back
 * 07. Class0 should have no error markers
 */
//@formatter:on
@Test
public void testSuperClassRenamed() throws Exception {
	logger.info("BuilderParticipantPluginUITest.testSuperClassRenamed");
	// create project and test files
	final IProject project = createJSProject("testSuperClassRenamed");
	IFolder folder = configureProjectWithXtext(project);

	IFolder moduleFolder = createFolder(folder, InheritanceTestFiles.inheritanceModule());

	IFile parentFile = createTestFile(moduleFolder, "Parent", InheritanceTestFiles.Parent());
	assertMarkers("Parent file should have no errors", parentFile, 0);
	IFile childFile = createTestFile(moduleFolder, "Child", InheritanceTestFiles.Child());
	assertMarkers("Child file should have no errors", childFile, 0);

	// open editors of test files
	IWorkbenchPage page = EclipseUIUtils.getActivePage();
	XtextEditor parentFileXtextEditor = openAndGetXtextEditor(parentFile, page);
	List<Resource.Diagnostic> errors = getEditorErrors(parentFileXtextEditor);
	assertEquals("Editor of parent should have no errors", 0, errors.size());
	XtextEditor childFileXtextEditor = openAndGetXtextEditor(childFile, page);
	errors = getEditorErrors(childFileXtextEditor);
	assertEquals("Editor of child should have no errors", 0, errors.size());

	parentFileXtextEditor.close(true);

	parentFile.move(new Path("Parent2" + "." + N4JSGlobals.N4JS_FILE_EXTENSION), true, true, monitor());
	moduleFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor());
	waitForAutoBuild();
	waitForUpdateEditorJob();

	assertFalse("Parent.n4js doesn't exist anymore",
			moduleFolder.getFile(new Path("Parent" + "." + N4JSGlobals.N4JS_FILE_EXTENSION)).exists());
	IFile movedParentFile = moduleFolder.getFile("Parent2" + "." + N4JSGlobals.N4JS_FILE_EXTENSION);
	assertTrue("Parent2.n4js does exist", movedParentFile.exists());

	errors = getEditorErrors(childFileXtextEditor);
	assertEquals("Editor of child should have got error markers",
			Sets.newHashSet(
					"line 1: Cannot resolve plain module specifier (without project name as first segment): no matching module found.",
					"line 2: Couldn't resolve reference to Type 'ParentObjectLiteral'."),
			toSetOfStrings(errors));

	movedParentFile.move(new Path("Parent" + "." + N4JSGlobals.N4JS_FILE_EXTENSION), true, true, monitor());
	moduleFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor());
	waitForAutoBuild();
	waitForUpdateEditorJob();
	assertTrue("Parent.n4js does exist",
			moduleFolder.getFile(new Path("Parent" + "." + N4JSGlobals.N4JS_FILE_EXTENSION)).exists());

	errors = getEditorErrors(childFileXtextEditor);
	assertEquals("Editor of child should have no errors", 0, errors.size());
}
 
Example 17
Source File: EquinoxApplicationProcessor.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void processLocal ( final IFolder output, final IProgressMonitor parentMonitor ) throws Exception
{
    final IProgressMonitor monitor = new SubProgressMonitor ( parentMonitor, 13 );

    // create context

    final OscarContext ctx = createContext ();

    // generate common content

    new SecurityProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new JdbcUserServiceModuleProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new EventStoragePostgresModuleProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new EventStorageJdbcModuleProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new EventInjectorJdbcProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new EventInjectorPostgresProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new ConnectionProcessor ( this.app, ctx ).process ();
    new ExporterProcessor ( this.app, ctx ).process ();

    // generate based on processors

    final Collection<OscarProcessor> processors = createProcessors ();
    monitor.worked ( 1 ); // COUNT:1
    {
        final SubProgressMonitor subMonitor = new SubProgressMonitor ( monitor, 1 ); // COUNT:1
        subMonitor.beginTask ( "Process application modules", processors.size () );

        for ( final OscarProcessor processor : processors )
        {
            processor.process ( ctx, this.app, subMonitor );
            subMonitor.worked ( 1 );
        }
        subMonitor.done ();
    }

    // generate custom content

    processForContext ( ctx, output, monitor );

    // write out oscar context

    final OscarWriter writer = new OscarWriter ( ctx.getData (), ctx.getIgnoreFields () );
    monitor.worked ( 1 ); // COUNT:1

    final IFile file = output.getFile ( "configuration.oscar" ); //$NON-NLS-1$
    try ( FileOutputStream fos = new FileOutputStream ( file.getRawLocation ().toOSString () ) )
    {
        writer.write ( fos );
    }
    monitor.worked ( 1 ); // COUNT:1

    final IFile jsonFile = output.getFile ( "data.json" ); //$NON-NLS-1$
    try ( final FileOutputStream fos = new FileOutputStream ( jsonFile.getRawLocation ().toOSString () ) )
    {
        OscarWriter.writeData ( ctx.getData (), fos );
    }
    monitor.worked ( 1 ); // COUNT:1

    // write out profile
    new P2ProfileProcessor ( this.app ).process ( output.getLocation ().toFile (), monitor );
    monitor.worked ( 1 ); // COUNT:1

    // refresh
    output.refreshLocal ( IResource.DEPTH_INFINITE, monitor );

    monitor.done ();
}
 
Example 18
Source File: DriverProcessor.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void process ( final String phase, final IFolder baseDir, final IProgressMonitor monitor, final Map<String, String> properties ) throws Exception
{
    if ( phase != null && !"process".equals ( phase ) )
    {
        return;
    }

    final String name = makeName ();

    final IFolder output = baseDir.getFolder ( new Path ( name ) );
    output.create ( true, true, null );

    final IFile exporterFile = output.getFile ( "exporter.xml" ); //$NON-NLS-1$
    final IFile propFile = output.getFile ( "application.properties" ); //$NON-NLS-1$

    final DocumentRoot root = ExporterFactory.eINSTANCE.createDocumentRoot ();

    final ConfigurationType cfg = ExporterFactory.eINSTANCE.createConfigurationType ();
    root.setConfiguration ( cfg );

    final HiveType hive = ExporterFactory.eINSTANCE.createHiveType ();
    cfg.getHive ().add ( hive );
    hive.setRef ( getHiveId () );

    final HiveConfigurationType hiveCfg = ExporterFactory.eINSTANCE.createHiveConfigurationType ();
    hive.setConfiguration ( hiveCfg );

    addConfiguration ( hiveCfg );

    for ( final Endpoint ep : this.driver.getEndpoints () )
    {
        addEndpoint ( hive, ep );
    }

    // write exporter file
    new ModelWriter ( root ).store ( URI.createPlatformResourceURI ( exporterFile.getFullPath ().toString (), true ) );
    exporterFile.refreshLocal ( 1, monitor );

    // write application properties
    if ( propFile.exists () )
    {
        propFile.delete ( true, monitor );
    }
    final Properties p = new Properties ();
    fillProperties ( p );
    if ( !p.isEmpty () )
    {
        try (FileOutputStream fos = new FileOutputStream ( propFile.getRawLocation ().toOSString () ))
        {
            p.store ( fos, "Created by the Eclipse SCADA world generator" );
        }
        propFile.refreshLocal ( 1, monitor );
    }
}
 
Example 19
Source File: IntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testJavaChangeTriggersBuild() throws Exception {
	foo_project = createJavaProject("foo");
	IJavaProject zonkProject = createJavaProject("zonk");
	bar_project = createJavaProjectWithRootSrc("bar");

	addProjectReference(bar_project, zonkProject);
	IClasspathEntry classpathEntry = JavaCore.newProjectEntry(foo_project.getPath(), true);
	workspace.addToClasspath(zonkProject, classpathEntry);

	IFolder javaPackage = foo_project.getProject().getFolder("src").getFolder("pack");
	javaPackage.create(true, true, null);
	IFile javaFile = javaPackage.getFile("Type.java");
	javaFile.create(new StringInputStream("package pack; public class Type {}"), true, monitor());

	IFolder dslFolder = bar_project.getProject().getFolder("src");
	IFile dslFile = dslFolder.getFile("Dsl.typesAssistTest");
	dslFile.create(new StringInputStream("default pack.Type"), true, monitor());

	build();
	assertEquals(printMarkers(dslFile), 0, countMarkers(dslFile));

	javaFile.setContents(new StringInputStream("package pack; class X {}"), true, true, null);

	build();
	// Xtext proxy validation and EObjectValidator proxy validation
	assertEquals(2, countMarkers(dslFile));

	javaFile.setContents(new StringInputStream("package pack; public class Type {}"), true, true, null);

	build();
	assertEquals(0, countMarkers(dslFile));

	workspace.removeClasspathEntry(zonkProject, classpathEntry);

	build();
	// Xtext proxy validation and EObjectValidator proxy validation
	assertEquals(2, countMarkers(dslFile));

	workspace.addToClasspath(zonkProject, classpathEntry);
	build();
	assertEquals(0, countMarkers(dslFile));
}
 
Example 20
Source File: Model.java    From tlaplus with MIT License 3 votes vote down vote up
/**
    * Returns a handle to the output file {@link ModelHelper#TE_TRACE_SOURCE} used by the
    * trace explorer to retrieve the trace from the most recent run of TLC on
    * the config.
    * 
    * Note that this is a handle-only operation. The file need not exist in the
    * underlying file system.
    * 
    * @return
    */
public IFile getTraceSourceFile() {
	final IFolder targetFolder = getTargetDirectory();
	if (targetFolder != null && targetFolder.exists()) {
		final IFile logFile = targetFolder.getFile(ModelHelper.TE_TRACE_SOURCE);
		Assert.isNotNull(logFile);
		return logFile;
	}
	return null;
}