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);
}
}
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;
}
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);
}
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);
}
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;
}
Aggregations