Search in sources :

Example 1 with SourceFolderDescriptor

use of org.eclipse.xtext.xtext.wizard.SourceFolderDescriptor in project xtext-core by eclipse.

the class CliProjectsCreator method createProject.

public void createProject(ProjectDescriptor project) {
    Preconditions.checkNotNull(lineDelimiter, "lineDelimiter may not be null");
    try {
        File projectRoot = new File(project.getLocation());
        projectRoot.mkdirs();
        for (AbstractFile f : project.getFiles()) {
            String outletPath = project.getConfig().getSourceLayout().getPathFor(f.getOutlet());
            String projectRelativePath = outletPath + "/" + f.getRelativePath();
            File file = new File(projectRoot, projectRelativePath);
            file.getParentFile().mkdirs();
            if (f instanceof TextFile) {
                String normalizedContent = ((TextFile) f).getContent().replace(Strings.newLine(), lineDelimiter);
                Files.asCharSink(file, project.getConfig().getEncoding()).write(normalizedContent);
            } else if (f instanceof BinaryFile) {
                Files.write(Resources.toByteArray(((BinaryFile) f).getContent()), file);
            }
            if (f.isExecutable()) {
                file.setExecutable(true);
            }
        }
        for (SourceFolderDescriptor folder : project.getSourceFolders()) {
            new File(projectRoot, folder.getPath()).mkdirs();
        }
    } catch (IOException e) {
        throw Exceptions.sneakyThrow(e);
    }
}
Also used : AbstractFile(org.eclipse.xtext.xtext.wizard.AbstractFile) SourceFolderDescriptor(org.eclipse.xtext.xtext.wizard.SourceFolderDescriptor) TextFile(org.eclipse.xtext.xtext.wizard.TextFile) IOException(java.io.IOException) BinaryFile(org.eclipse.xtext.xtext.wizard.BinaryFile) TextFile(org.eclipse.xtext.xtext.wizard.TextFile) AbstractFile(org.eclipse.xtext.xtext.wizard.AbstractFile) File(java.io.File) BinaryFile(org.eclipse.xtext.xtext.wizard.BinaryFile)

Example 2 with SourceFolderDescriptor

use of org.eclipse.xtext.xtext.wizard.SourceFolderDescriptor in project xtext-eclipse by eclipse.

the class XtextProjectCreator method configureJavaProject.

private void configureJavaProject(ProjectDescriptor descriptor, JavaProjectFactory factory) {
    configurePlainProject(descriptor, factory);
    factory.addProjectNatures(XtextProjectHelper.NATURE_ID);
    factory.addBuilderIds(XtextProjectHelper.BUILDER_ID);
    factory.addProjectNatures(JavaCore.NATURE_ID);
    factory.addBuilderIds(JavaCore.BUILDER_ID);
    for (SourceFolderDescriptor sourceFolder : descriptor.getSourceFolders()) {
        String output = sourceFolder.isTest() ? (needsM2eIntegration(descriptor) ? "target/test-classes" : "test-bin") : null;
        factory.addSourceFolder(sourceFolder.getPath(), output, sourceFolder.isTest());
    }
    factory.setJreContainerEntry(JREContainerProvider.getJREContainerEntry(descriptor.getBree()));
    if (needsM2eIntegration(descriptor)) {
        factory.setDefaultOutput("target/classes");
        if (!descriptor.isEclipsePluginProject()) {
            factory.addClasspathEntries(JavaCore.newContainerEntry(new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER")));
        }
    }
    if (needsBuildshipIntegration(descriptor) && !descriptor.isEclipsePluginProject()) {
        factory.addClasspathEntries(JavaCore.newContainerEntry(new Path("org.eclipse.buildship.core.gradleclasspathcontainer")));
    }
    if (requiresJUnitLibContainer(descriptor)) {
        JUnitVersion junitVersion = descriptor.getConfig().getJunitVersion();
        factory.addClasspathEntries(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.junit.JUNIT_CONTAINER").append(Integer.toString(junitVersion.getVersion())), new IAccessRule[0], new IClasspathAttribute[] { JavaCore.newClasspathAttribute("test", "true") }, false));
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) SourceFolderDescriptor(org.eclipse.xtext.xtext.wizard.SourceFolderDescriptor) JUnitVersion(org.eclipse.xtext.util.JUnitVersion) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Aggregations

SourceFolderDescriptor (org.eclipse.xtext.xtext.wizard.SourceFolderDescriptor)2 File (java.io.File)1 IOException (java.io.IOException)1 Path (org.eclipse.core.runtime.Path)1 IAccessRule (org.eclipse.jdt.core.IAccessRule)1 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)1 JUnitVersion (org.eclipse.xtext.util.JUnitVersion)1 AbstractFile (org.eclipse.xtext.xtext.wizard.AbstractFile)1 BinaryFile (org.eclipse.xtext.xtext.wizard.BinaryFile)1 TextFile (org.eclipse.xtext.xtext.wizard.TextFile)1