Search in sources :

Example 11 with SpecFile

use of org.eclipse.n4js.jsdoc2spec.SpecFile in project n4js by eclipse.

the class JSDoc2AdocFullTest method fullTest.

@Override
@SuppressWarnings("unused")
protected void fullTest(String projectId) throws IOException, InterruptedException, InterruptedException {
    String systemSeparator = System.getProperty("line.separator", "\n");
    try {
        for (String lsep : new String[] { "\n", "\r\n", "\r" }) {
            System.setProperty("line.separator", lsep);
            String expectationFileName = projectId + "/expected.adoc";
            workspace = new FileBasedWorkspace(resourceSetProvider, classpathPackageManager);
            URI uriProject = URI.createFileURI(new File(TESTRESOURCES + projectId).getAbsolutePath());
            workspace.registerProject(uriProject);
            N4JSModel model = new N4JSModel(workspace);
            injector.injectMembers(model);
            runtimeCore = new N4JSRuntimeCore(workspace, model);
            IN4JSProject project = runtimeCore.findProject(uriProject).get();
            assertNotNull("Project not found", project);
            Collection<SpecFile> specChangeSet = jSDoc2SpecProcessor.convert(new File(TESTRESOURCES), Collections.singleton(project), (p) -> resourceSetProvider.get(), SubMonitorMsg.nullProgressMonitor());
            String adocRootName = TESTRESOURCES + projectId + "/expectedADoc";
            Collection<String> expectedFileNames = getExpectedFileNames(adocRootName, specChangeSet);
            assertFalse(expectedFileNames.isEmpty());
            File adocRoot = new File(adocRootName);
            String completeActual = "";
            String completeExpected = "";
            for (SpecFile specFile : specChangeSet) {
                String expectedFile = getExpectedFile(expectedFileNames, specFile);
                if (expectedFile == null)
                    continue;
                String fullExpectationFileName = adocRoot.toPath().resolve(expectedFile).toString();
                String expectedADoc = Files.readFileIntoString(fullExpectationFileName);
                String actualADoc = specFile.getNewContent();
                if (UPDATE_EXPECTION && !actualADoc.equals(expectedADoc)) {
                    expectedADoc = actualADoc;
                    Files.writeStringIntoFile(fullExpectationFileName, expectedADoc);
                    System.out.println("Updated expectation " + fullExpectationFileName);
                }
                completeActual += "\n//////// " + expectedFile + " ////////\n";
                completeActual += actualADoc;
                completeExpected += "\n//////// " + expectedFile + " ////////\n";
                completeExpected += expectedADoc;
            }
            assertEqualsIgnoreWS(completeExpected, completeActual);
        }
    } finally {
        System.setProperty("line.separator", systemSeparator);
    }
}
Also used : FileBasedWorkspace(org.eclipse.n4js.internal.FileBasedWorkspace) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) N4JSRuntimeCore(org.eclipse.n4js.internal.N4JSRuntimeCore) URI(org.eclipse.emf.common.util.URI) SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile) File(java.io.File) N4JSModel(org.eclipse.n4js.internal.N4JSModel) SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile)

Example 12 with SpecFile

use of org.eclipse.n4js.jsdoc2spec.SpecFile in project n4js by eclipse.

the class TaskGenerateAdoc method getModulesCountTotal.

int getModulesCountTotal() {
    File docRootDir = configAdocPage.getConfig().getDocRootDir();
    String modulesDir = docRootDir + SEP + DIR_ADOC_GEN + SEP + DIR_MODULES;
    List<String> moduleFileNames = FileSystem.getAdocFileNames(modulesDir);
    Collections.sort(moduleFileNames);
    int changedModuleFiles = 0;
    int updatedModuleFiles = 0;
    if (specChangeSet != null) {
        for (SpecFile specFile : specChangeSet) {
            if (specFile instanceof SpecModuleFile) {
                changedModuleFiles++;
                if (moduleFileNames.contains(specFile.getFile().getName())) {
                    updatedModuleFiles++;
                }
            }
        }
    }
    return moduleFileNames.size() + changedModuleFiles - updatedModuleFiles;
}
Also used : SpecModuleFile(org.eclipse.n4js.jsdoc2spec.adoc.SpecModuleFile) SpecModuleFile(org.eclipse.n4js.jsdoc2spec.adoc.SpecModuleFile) SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile) File(java.io.File) SpecIndexFile(org.eclipse.n4js.jsdoc2spec.adoc.SpecIndexFile) SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile)

Example 13 with SpecFile

use of org.eclipse.n4js.jsdoc2spec.SpecFile in project n4js by eclipse.

the class TaskGenerateAdoc method computeChangeSet.

/**
 * Side effect: sets {@link #specChangeSet}
 */
private void computeChangeSet(SubMonitorMsg completeProgress) throws IOException, InterruptedException {
    specChangeSet = new TreeSet<>();
    completeProgress.subTask("Reading existing documentation ...");
    SubMonitorMsg readSpecProgress = completeProgress.newChild(1);
    jsDoc2SpecProcessor.setRootDir(configAdoc.getDocRootDir());
    CheckCanceled.checkUserCanceled(readSpecProgress);
    readSpecProgress.done();
    completeProgress.subTask("Computing updates ...");
    SubMonitorMsg compUpdtsProgress = completeProgress.newChild(1);
    Collection<SpecFile> changes = jsDoc2SpecProcessor.computeUpdates(specInfos, compUpdtsProgress);
    CheckCanceled.checkUserCanceled(compUpdtsProgress);
    compUpdtsProgress.done();
    specChangeSet.addAll(changes);
}
Also used : SubMonitorMsg(org.eclipse.n4js.jsdoc2spec.SubMonitorMsg) SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile)

Example 14 with SpecFile

use of org.eclipse.n4js.jsdoc2spec.SpecFile in project n4js by eclipse.

the class JSDoc2ADocSpecProcessor method insertIntoSpecModuleFile.

private void insertIntoSpecModuleFile(TreeMap<String, SpecFile> specFiles, Map<String, SpecSection> specsByKey, SpecIdentifiableElementSection specSection) {
    String specKey = specSection.getSpecKey();
    specsByKey.put(specKey, specSection);
    String moduleKey = specSection.getSpecModuleKey();
    if (!specFiles.containsKey(moduleKey)) {
        SpecModuleFile scf = new SpecModuleFile(specSection.getFile());
        specFiles.put(moduleKey, scf);
    }
    SpecFile scf = specFiles.get(moduleKey);
    specSection.generateADocText(adocFactory, specsByKey);
    scf.add(specSection);
}
Also used : SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile)

Example 15 with SpecFile

use of org.eclipse.n4js.jsdoc2spec.SpecFile in project n4js by eclipse.

the class JSDoc2ADocSpecProcessor method filterChangedFiles.

/**
 * The wizard will only show files whose content changed. Also, only these files will be written to the file system.
 * The difference is computed by comparing both of the file's contents as strings.
 */
private Collection<SpecFile> filterChangedFiles(Collection<SpecFile> newSpecSet) throws IOException {
    List<SpecFile> changedFiles = new ArrayList<>();
    for (SpecFile scf : newSpecSet) {
        boolean fileExists = scf.getFile().exists();
        boolean fileChanged = !fileExists;
        if (fileExists) {
            String oldContent = Files.toString(scf.getFile(), Charsets.UTF_8).replace("\r\n", "\n");
            String newContent = scf.getNewContent();
            if (!oldContent.equals(newContent))
                fileChanged = true;
        }
        if (fileChanged)
            changedFiles.add(scf);
    }
    return changedFiles;
}
Also used : ArrayList(java.util.ArrayList) SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile)

Aggregations

SpecFile (org.eclipse.n4js.jsdoc2spec.SpecFile)18 File (java.io.File)10 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)2 SubMonitorMsg (org.eclipse.n4js.jsdoc2spec.SubMonitorMsg)2 SpecIndexFile (org.eclipse.n4js.jsdoc2spec.adoc.SpecIndexFile)2 SpecModuleFile (org.eclipse.n4js.jsdoc2spec.adoc.SpecModuleFile)2 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 DiffNode (org.eclipse.compare.structuremergeviewer.DiffNode)1 URI (org.eclipse.emf.common.util.URI)1 FileBasedWorkspace (org.eclipse.n4js.internal.FileBasedWorkspace)1 N4JSModel (org.eclipse.n4js.internal.N4JSModel)1 N4JSRuntimeCore (org.eclipse.n4js.internal.N4JSRuntimeCore)1 SpecElementRef (org.eclipse.n4js.jsdoc2spec.SpecElementRef)1 SpecInfo (org.eclipse.n4js.jsdoc2spec.SpecInfo)1 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)1