diff options
author | Adrian Sacchi | 2014-01-30 17:47:04 +0000 |
---|---|---|
committer | Judith Gull | 2014-02-04 10:13:00 +0000 |
commit | 3688e754e1384965ad3deec54e7b43eadefda725 (patch) | |
tree | 6a78040668589d8c7f3b2e940c566dd4947fa6f5 | |
parent | f3ef4d7eed933d761117ffabd9d7cc17acd7d232 (diff) | |
download | org.eclipse.scout.rt-3688e754e1384965ad3deec54e7b43eadefda725.tar.gz org.eclipse.scout.rt-3688e754e1384965ad3deec54e7b43eadefda725.tar.xz org.eclipse.scout.rt-3688e754e1384965ad3deec54e7b43eadefda725.zip |
bug 426992: [Spec] Additional Output as linear file
https://bugs.eclipse.org/bugs/show_bug.cgi?id=426992
Change-Id: I80ac9ec5c9c2f9ddc54f7311a321152d7d969c06
Signed-off-by: Adrian Sacchi <adrian.sacchi@bsiag.com>
Reviewed-on: https://git.eclipse.org/r/21355
Tested-by: Hudson CI
Reviewed-by: Judith Gull <jgu@bsiag.com>
IP-Clean: Judith Gull <jgu@bsiag.com>
10 files changed, 518 insertions, 74 deletions
diff --git a/org.eclipse.scout.commons.test/src/org/eclipse/scout/commons/IOUtilityTest.java b/org.eclipse.scout.commons.test/src/org/eclipse/scout/commons/IOUtilityTest.java index 02f02ca43c..fabeefde1a 100644 --- a/org.eclipse.scout.commons.test/src/org/eclipse/scout/commons/IOUtilityTest.java +++ b/org.eclipse.scout.commons.test/src/org/eclipse/scout/commons/IOUtilityTest.java @@ -10,6 +10,7 @@ ******************************************************************************/ package org.eclipse.scout.commons; +import static org.eclipse.scout.rt.testing.commons.ScoutAssert.assertListEquals; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -17,8 +18,14 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.PrintWriter; import java.io.RandomAccessFile; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.eclipse.scout.commons.exception.ProcessingException; import org.eclipse.scout.commons.utility.TestUtility; @@ -30,9 +37,10 @@ import org.junit.Test; * @since 3.9.1 */ public class IOUtilityTest { - private static final byte[] content = new byte[]{1, 2, 3, 4}; - private static String filename = "myTempFile"; - private static String extension = ".tmp"; + private static final String[] LINES = {"one", "two", "three", "lorem ipsum sit amet"}; + private static final byte[] CONTENT = new byte[]{1, 2, 3, 4}; + private static final String FILENAME = "myTempFile"; + private static final String EXTENSION = ".tmp"; @Test public void testGetContentInEncoding() throws ProcessingException { @@ -64,46 +72,75 @@ public class IOUtilityTest { @Test public void testCreateNewTempFile() throws ProcessingException, Throwable { - File tempFile = IOUtility.createTempFile(filename + extension, content); - assertTrue(tempFile.getName().endsWith(filename + extension)); - assertArrayEquals(content, readFile(tempFile)); - tempFile.delete(); + File tempFile = null; + try { + tempFile = IOUtility.createTempFile(FILENAME + EXTENSION, CONTENT); + assertTrue(tempFile.getName().endsWith(FILENAME + EXTENSION)); + assertArrayEquals(CONTENT, readFile(tempFile)); + } + finally { + TestUtility.deleteTempFile(tempFile); + } - tempFile = IOUtility.createTempFile(filename, extension, content); - assertTrue(tempFile.getName().startsWith(filename)); - assertTrue(tempFile.getName().endsWith(extension)); - assertArrayEquals(content, readFile(tempFile)); - tempFile.delete(); + try { + tempFile = IOUtility.createTempFile(FILENAME, EXTENSION, CONTENT); + assertTrue(tempFile.getName().startsWith(FILENAME)); + assertTrue(tempFile.getName().endsWith(EXTENSION)); + assertArrayEquals(CONTENT, readFile(tempFile)); + tempFile.delete(); + } + finally { + TestUtility.deleteTempFile(tempFile); + } } @Test public void testCreateNewTempFileNoContent() throws ProcessingException, Throwable { - File tempFile = IOUtility.createTempFile(filename + extension, null); - assertTrue(tempFile.getName().endsWith(filename + extension)); - assertArrayEquals(new byte[]{}, readFile(tempFile)); - tempFile.delete(); + File tempFile = null; + try { + tempFile = IOUtility.createTempFile(FILENAME + EXTENSION, null); + assertTrue(tempFile.getName().endsWith(FILENAME + EXTENSION)); + assertArrayEquals(new byte[]{}, readFile(tempFile)); + } + finally { + TestUtility.deleteTempFile(tempFile); + } - tempFile = IOUtility.createTempFile(filename, extension, null); - assertTrue(tempFile.getName().startsWith(filename)); - assertTrue(tempFile.getName().endsWith(extension)); - assertArrayEquals(new byte[]{}, readFile(tempFile)); - tempFile.delete(); + try { + tempFile = IOUtility.createTempFile(FILENAME, EXTENSION, null); + assertTrue(tempFile.getName().startsWith(FILENAME)); + assertTrue(tempFile.getName().endsWith(EXTENSION)); + assertArrayEquals(new byte[]{}, readFile(tempFile)); + } + finally { + TestUtility.deleteTempFile(tempFile); + } } @Test public void testCreateNewTempFileEmptyFilename() throws ProcessingException, Throwable { - File tempFile = IOUtility.createTempFile("", content); - assertTrue(tempFile.getName().endsWith(".tmp")); - assertArrayEquals(content, readFile(tempFile)); - tempFile.delete(); + File tempFile = null; + try { + tempFile = IOUtility.createTempFile("", CONTENT); + assertTrue(tempFile.getName().endsWith(".tmp")); + assertArrayEquals(CONTENT, readFile(tempFile)); + } + finally { + TestUtility.deleteTempFile(tempFile); + } } @Test public void testCreateNewTempFileNullParameter() throws ProcessingException, Throwable { - File tempFile = IOUtility.createTempFile(null, content); - assertTrue(tempFile.getName().endsWith(".tmp")); - assertArrayEquals(content, readFile(tempFile)); - tempFile.delete(); + File tempFile = null; + try { + tempFile = IOUtility.createTempFile(null, CONTENT); + assertTrue(tempFile.getName().endsWith(".tmp")); + assertArrayEquals(CONTENT, readFile(tempFile)); + } + finally { + TestUtility.deleteTempFile(tempFile); + } } @Test @@ -158,4 +195,168 @@ public class IOUtilityTest { assertEquals("a test with multiple spaces", IOUtility.urlDecode("a%20test%20%20with%20%20%20multiple%20%20%20%20spaces")); assertEquals("Expected UTF-8 charset", "öäüéàè", IOUtility.urlDecode("%C3%B6%C3%A4%C3%BC%C3%A9%C3%A0%C3%A8")); } + + @Test + public void testReadLines() throws ProcessingException, FileNotFoundException { + File tempFile = null; + try { + tempFile = createTextTempFile(); + + List<String> readLines = IOUtility.readLines(tempFile); + String[] readLinesArray = readLines.toArray(new String[readLines.size()]); + assertArrayEquals("arrays with read lines not as expected", LINES, readLinesArray); + } + finally { + TestUtility.deleteTempFile(tempFile); + } + } + + private File createTextTempFile() throws ProcessingException, FileNotFoundException { + File tempFile; + tempFile = IOUtility.createTempFile(FILENAME, EXTENSION, null); + PrintWriter printWriter = new PrintWriter(tempFile); + for (String line : LINES) { + printWriter.println(line); + } + printWriter.close(); + return tempFile; + } + + @Test + public void testReadLinesEmptyFile() throws ProcessingException, FileNotFoundException { + File tempFile = null; + try { + tempFile = IOUtility.createTempFile(FILENAME, EXTENSION, null); + List<String> readLines = IOUtility.readLines(tempFile); + assertTrue("Expected an empty list when reading an empty file.", readLines.isEmpty()); + } + finally { + TestUtility.deleteTempFile(tempFile); + } + } + + @Test + public void testReadLinesNonExistingFile() { + boolean processingExceptionOccured = false; + try { + IOUtility.readLines(new File("doesNotExist")); + } + catch (ProcessingException e) { + processingExceptionOccured = true; + } + assertTrue("Exptected a ProcessingException for non existing file.", processingExceptionOccured); + } + + @Test + public void testAppendFile() throws FileNotFoundException, ProcessingException { + File tempFile = null; + File tempFile2 = null; + PrintWriter pw = null; + try { + tempFile = createTextTempFile(); + tempFile2 = createTextTempFile(); + + pw = new PrintWriter(new FileOutputStream(tempFile, true)); + IOUtility.appendFile(pw, tempFile2); + pw.close(); + + List<String> readLines = IOUtility.readLines(tempFile); + List<String> expectedLines = new ArrayList<String>(); + expectedLines.addAll(Arrays.asList(LINES)); + expectedLines.addAll(Arrays.asList(LINES)); + assertListEquals(expectedLines, readLines); + } + finally { + TestUtility.deleteTempFile(tempFile); + TestUtility.deleteTempFile(tempFile2); + } + } + + @Test + public void testAppendEmptyFile() throws FileNotFoundException, ProcessingException { + File tempFile = null; + File tempFile2 = null; + PrintWriter pw = null; + try { + tempFile = createTextTempFile(); + tempFile2 = IOUtility.createTempFile(FILENAME, EXTENSION, null); + + pw = new PrintWriter(new FileOutputStream(tempFile, true)); + IOUtility.appendFile(pw, tempFile2); + pw.close(); + + List<String> readLines = IOUtility.readLines(tempFile); + List<String> expectedLines = new ArrayList<String>(); + expectedLines.addAll(Arrays.asList(LINES)); + assertListEquals(expectedLines, readLines); + } + finally { + TestUtility.deleteTempFile(tempFile); + TestUtility.deleteTempFile(tempFile2); + } + } + + @Test + public void testAppendNonExistingFile() throws FileNotFoundException, ProcessingException { + File tempFile = null; + File tempFile2 = new File("doesNotExist"); + PrintWriter pw = null; + try { + tempFile = createTextTempFile(); + pw = new PrintWriter(new FileOutputStream(tempFile, true)); + boolean processingExceptionOccured = false; + try { + IOUtility.appendFile(pw, tempFile2); + } + catch (ProcessingException e) { + processingExceptionOccured = true; + } + finally { + pw.close(); + } + assertTrue("Exptected a ProcessingException for non existing file.", processingExceptionOccured); + + } + finally { + TestUtility.deleteTempFile(tempFile); + } + } + + @Test + public void testAppendSameFile() throws FileNotFoundException, ProcessingException { + File tempFile = null; + PrintWriter pw = null; + try { + tempFile = createTextTempFile(); + + pw = new PrintWriter(new FileOutputStream(tempFile, true)); + IOUtility.appendFile(pw, tempFile); + IOUtility.appendFile(pw, tempFile); + pw.flush(); + List<String> expectedLines = new ArrayList<String>(); + expectedLines.addAll(Arrays.asList(LINES)); + expectedLines.addAll(Arrays.asList(LINES)); + expectedLines.addAll(Arrays.asList(LINES)); + List<String> readLines = IOUtility.readLines(tempFile); + // expect 3x original content + assertListEquals(expectedLines, readLines); + + IOUtility.appendFile(pw, tempFile); + pw.close(); + + expectedLines.addAll(Arrays.asList(LINES)); + expectedLines.addAll(Arrays.asList(LINES)); + expectedLines.addAll(Arrays.asList(LINES)); + readLines = IOUtility.readLines(tempFile); + // expect 6x original content + assertListEquals(expectedLines, readLines); + } + finally { + if (pw != null) { + pw.close(); + } + TestUtility.deleteTempFile(tempFile); + } + } + } diff --git a/org.eclipse.scout.commons/src/org/eclipse/scout/commons/IOUtility.java b/org.eclipse.scout.commons/src/org/eclipse/scout/commons/IOUtility.java index b77211a9d9..bd7a796d43 100644 --- a/org.eclipse.scout.commons/src/org/eclipse/scout/commons/IOUtility.java +++ b/org.eclipse.scout.commons/src/org/eclipse/scout/commons/IOUtility.java @@ -19,11 +19,13 @@ import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.PrintWriter; import java.io.Reader; import java.io.StringWriter; import java.io.UnsupportedEncodingException; @@ -32,6 +34,7 @@ import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.List; import org.eclipse.scout.commons.exception.ProcessingException; import org.eclipse.scout.commons.logger.IScoutLogger; @@ -621,4 +624,76 @@ public final class IOUtility { } return url; } + + /** + * Append a file to another. The provided {@link PrintWriter} will neither be flushed nor closed. + * <p> + * ATTENTION: Appending a file to itself using an autoflushing PrintWriter, will lead to an endless loop. (Appending a + * file to itself using a Printwriter without autoflushing is safe.) + * + * @param writer + * a PrintWriter for the destination file + * @param file + * source file + * @throws ProcessingException + * if an {@link IOException} occurs (e.g. if file does not exists) + */ + public static void appendFile(PrintWriter writer, File file) throws ProcessingException { + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(file)); + String line; + while ((line = reader.readLine()) != null) { + writer.println(line); + } + } + catch (IOException e) { + throw new ProcessingException("Error appending file: " + file.getName(), e); + } + finally { + if (reader != null) { + try { + reader.close(); + } + catch (IOException e) { + // ignore + } + } + } + + } + + /** + * @param file + * @return List containing all lines of the file as Strings + * @throws ProcessingException + * if an {@link IOException} occurs (e.g. if file does not exists) + */ + public static List<String> readLines(File file) throws ProcessingException { + ArrayList<String> sourceFiles; + sourceFiles = new ArrayList<String>(); + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new FileReader(file)); + String line; + while ((line = bufferedReader.readLine()) != null) { + sourceFiles.add(line); + } + } + catch (IOException e) { + throw new ProcessingException("Error reading config file.", e); + } + finally { + if (bufferedReader != null) { + try { + bufferedReader.close(); + } + catch (IOException e) { + // ignore + } + } + } + return sourceFiles; + } + } diff --git a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/AbstractSpecGen.java b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/AbstractSpecGen.java index 797708fc2d..fc45959542 100644 --- a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/AbstractSpecGen.java +++ b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/AbstractSpecGen.java @@ -14,7 +14,6 @@ import java.io.File; import java.io.Writer; import java.util.List; -import org.eclipse.scout.commons.ITypeWithClassId; import org.eclipse.scout.commons.exception.ProcessingException; import org.eclipse.scout.rt.spec.client.config.DefaultDocConfig; import org.eclipse.scout.rt.spec.client.config.IDocConfig; @@ -68,8 +67,4 @@ public class AbstractSpecGen { w.writeLinks(links); } - public String getId(ITypeWithClassId o) { - return o.classId(); - } - } diff --git a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/AbstractTablePageSpecGen.java b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/AbstractTablePageSpecGen.java index 1dabdcef9a..3bc216fae8 100644 --- a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/AbstractTablePageSpecGen.java +++ b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/AbstractTablePageSpecGen.java @@ -24,7 +24,7 @@ public abstract class AbstractTablePageSpecGen extends AbstractSpecGen { public void printAllFields() throws ProcessingException { IPageWithTable<? extends ITable> page = createAndStartTablePage(); IDocSection doc = generate(page); - write(doc, getId(page), new String[]{}, page.getClass().getSimpleName()); + write(doc, page.classId(), new String[]{}, page.getClass().getSimpleName()); } protected IDocSection generate(IPageWithTable<? extends ITable> page) { diff --git a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/LinearOutputPostProcessor.java b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/LinearOutputPostProcessor.java new file mode 100644 index 0000000000..b72443943d --- /dev/null +++ b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/LinearOutputPostProcessor.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2010 BSI Business Systems Integration AG. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * BSI Business Systems Integration AG - initial API and implementation + ******************************************************************************/ +package org.eclipse.scout.rt.spec.client; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Collections; +import java.util.List; + +import org.eclipse.scout.commons.IOUtility; +import org.eclipse.scout.commons.StringUtility; +import org.eclipse.scout.commons.exception.ProcessingException; +import org.eclipse.scout.commons.logger.IScoutLogger; +import org.eclipse.scout.commons.logger.ScoutLogManager; +import org.eclipse.scout.rt.spec.client.config.SpecFileConfig; +import org.osgi.framework.Bundle; + +/** + * A post processor for generating linear output files (mediawiki and html) + * <p> + * The generated output files will have the same base filename as the configuration file with differnt ending. + */ +public class LinearOutputPostProcessor extends AbstractSpecGen implements ISpecProcessor { + private static IScoutLogger LOG = ScoutLogManager.getLogger(LinearOutputPostProcessor.class); + private File m_configFile; + private File m_outputFile; + + /** + * @param configFile + * Filename of configuration file which will be searched in {@link SpecFileConfig#getRelativeSourceDirPath()} + * in all {@link SpecFileConfig#getSourceBundles()} according their priority. + * <p> + * The configuration file is expected to have the file ending <code>.config</code> + * @throws ProcessingException + */ + public LinearOutputPostProcessor(String configFile) throws ProcessingException { + List<Bundle> sourceBundles = getFileConfig().getSourceBundles(); + Collections.reverse(sourceBundles); + for (Bundle bundle : sourceBundles) { + List<String> fileList = SpecIOUtility.listFiles(bundle, getFileConfig().getRelativeSourceDirPath(), getConfigFileFilter(configFile)); + if (fileList.size() > 0) { + m_configFile = new File(getFileConfig().getSpecDir(), configFile); + SpecIOUtility.copyFile(bundle, getFileConfig().getRelativeSourceDirPath() + File.separator + configFile, m_configFile); + break; + } + } + if (m_configFile == null || !m_configFile.exists()) { + LOG.error("Configfile " + configFile + " could not be copied!"); + } + } + + private FilenameFilter getConfigFileFilter(final String configFile) { + return new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.equals(configFile); + } + }; + } + + @Override + public void process() throws ProcessingException { + if (m_configFile == null || !m_configFile.exists()) { + return; + } + String outputFileName = m_configFile.getName().replace(".config", ""); + List<String> sourceFiles = IOUtility.readLines(m_configFile); + if (!StringUtility.isNullOrEmpty(outputFileName)) { + PrintWriter writer = null; + m_outputFile = new File(getFileConfig().getMediawikiDir(), outputFileName + ".mediawiki"); + m_outputFile.delete(); + try { + m_outputFile.createNewFile(); + writer = new PrintWriter(m_outputFile); + for (String sourceFile : sourceFiles) { + String mediawikiFile = sourceFile + ".mediawiki"; + LOG.info("appending file. " + mediawikiFile); + IOUtility.appendFile(writer, new File(getFileConfig().getMediawikiDir(), mediawikiFile)); + writer.flush(); + } + } + catch (IOException e) { + throw new ProcessingException("Error creating output file.", e); + } + finally { + if (writer != null) { + writer.close(); + } + } + } + } + + // TODO ASA what about links? +// private void replaceLinks(File f) throws ProcessingException { +// MediawikiAnchorCollector c = new MediawikiAnchorCollector(f); +// c.replaceLinks(f, getFileConfig().getLinksFile()); +// } +// +// private void replaceWikiFileLinks(File htmlFile) throws ProcessingException { +// HashMap<String, String> map = new HashMap<String, String>(); +// map.put("/wiki/", ""); +// map.put(".mediawiki", ".html"); +// SpecIOUtility.replaceAll(htmlFile, map); +// } + +} diff --git a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/AbstractManualSpec.java b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/ManualSpecTest.java index 2e635db602..0150916b6a 100644 --- a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/AbstractManualSpec.java +++ b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/ManualSpecTest.java @@ -15,12 +15,17 @@ import java.io.FilenameFilter; import org.eclipse.scout.commons.exception.ProcessingException; import org.eclipse.scout.rt.spec.client.out.mediawiki.MediawikiAnchorCollector; +import org.junit.Test; import org.osgi.framework.Bundle; -/** - * - */ -public abstract class AbstractManualSpec extends AbstractSpecGen { +// TODO ASA javadoc +public class ManualSpecTest extends AbstractSpecGen { + + @Test + public void copy() throws ProcessingException { + copyMediawikiFiles(); + copyImages(); + } protected void copyImages() throws ProcessingException { File dest = getFileConfig().getImageDir(); diff --git a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/SpecPostProcessor.java b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/MediawikiPostProcessor.java index 746048e478..93a2b7793c 100644 --- a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/SpecPostProcessor.java +++ b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/MediawikiPostProcessor.java @@ -23,10 +23,13 @@ import org.eclipse.scout.rt.spec.client.out.mediawiki.MediawikiAnchorCollector; import org.eclipse.scout.rt.spec.client.out.mediawiki.MediawikiLinkPostProcessor; /** - * A post processor for replacing link tags to point to the generated files. + * A post processor for mediawiki files which performs the following tasks: + * <p> + * <li>Replace link tags to point to the generated files. + * <li>Convert all mediawiki files to html files */ -public class SpecPostProcessor extends AbstractSpecGen implements ISpecProcessor { - private static IScoutLogger LOG = ScoutLogManager.getLogger(SpecPostProcessor.class); +public class MediawikiPostProcessor extends AbstractSpecGen implements ISpecProcessor { + private static IScoutLogger LOG = ScoutLogManager.getLogger(MediawikiPostProcessor.class); @Override public void process() throws ProcessingException { diff --git a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/SpecIOUtility.java b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/SpecIOUtility.java index 4162b8d06e..77c9a3ad69 100644 --- a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/SpecIOUtility.java +++ b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/SpecIOUtility.java @@ -42,12 +42,15 @@ import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.scout.commons.CollectionUtility; import org.eclipse.scout.commons.exception.ProcessingException; +import org.eclipse.scout.commons.logger.IScoutLogger; +import org.eclipse.scout.commons.logger.ScoutLogManager; import org.osgi.framework.Bundle; /** * Some utilities for files */ public final class SpecIOUtility { + private static final IScoutLogger LOG = ScoutLogManager.getLogger(SpecIOUtility.class); public static final String ENCODING = "utf-8"; private SpecIOUtility() { @@ -328,11 +331,16 @@ public final class SpecIOUtility { File bundleRoot = new File(resolvedFileBundleUri); File dir = new File(bundleRoot, relativePath); File[] files = dir.listFiles(filter); - for (File file : files) { - if (file.isFile()) { - fileNames.add(file.getName()); + if (files != null) { + for (File file : files) { + if (file.isFile()) { + fileNames.add(file.getName()); + } } } + else { + LOG.warn("Could not read directory: " + dir.getPath()); + } return fileNames; } diff --git a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/SpecJob.java b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/SpecJob.java index 82882c899f..e68c590efb 100644 --- a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/SpecJob.java +++ b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/SpecJob.java @@ -37,18 +37,25 @@ public class SpecJob extends Job { private static final long STARTUP_TIMEOUT_IN_MS = 60 * 1000L; private final long m_startupTimeout; protected final Class<? extends IClientSession> m_clientSessionClass; - private final SpecPostProcessor m_postProcessor; + private final ISpecProcessor[] m_postProcessors; - public SpecJob(Class<? extends IClientSession> clientSessionClass, String pluginName) { - this(clientSessionClass, STARTUP_TIMEOUT_IN_MS, new SpecPostProcessor()); + public SpecJob(Class<? extends IClientSession> clientSessionClass, String pluginName) throws ProcessingException { + this(clientSessionClass, STARTUP_TIMEOUT_IN_MS, new LinearOutputPostProcessor("SpecComplete.config"), new MediawikiPostProcessor()); } - public SpecJob(Class<? extends IClientSession> clientSessionClass, long startupTimeout, SpecPostProcessor postProcessor) { + /** + * Creates a SpecJob. The postProcessors will be executed in the order they are provided here. + * + * @param clientSessionClass + * @param startupTimeout + * @param postProcessors + */ + public SpecJob(Class<? extends IClientSession> clientSessionClass, long startupTimeout, ISpecProcessor... postProcessors) { super("Specification"); setSystem(true); m_clientSessionClass = clientSessionClass; m_startupTimeout = startupTimeout; - m_postProcessor = postProcessor; + m_postProcessors = postProcessors; } @Override @@ -117,16 +124,18 @@ public class SpecJob extends Job { } private void postProcess() { - try { - getPostProcessor().process(); - } - catch (ProcessingException e) { - LOG.error("Error during post Processing ", e); + for (ISpecProcessor processor : getPostProcessor()) { + try { + processor.process(); + } + catch (ProcessingException e) { + LOG.error("Error during post Processing ", e); + } } } - public SpecPostProcessor getPostProcessor() { - return m_postProcessor; + public ISpecProcessor[] getPostProcessor() { + return m_postProcessors; } } diff --git a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/config/SpecFileConfig.java b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/config/SpecFileConfig.java index faf0325834..c827a4dee8 100644 --- a/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/config/SpecFileConfig.java +++ b/org.eclipse.scout.rt.spec.client/src/org/eclipse/scout/rt/spec/client/config/SpecFileConfig.java @@ -21,6 +21,7 @@ import java.util.List; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IProduct; import org.eclipse.core.runtime.Platform; +import org.eclipse.scout.commons.StringUtility; import org.eclipse.scout.commons.exception.ProcessingException; import org.eclipse.scout.commons.logger.IScoutLogger; import org.eclipse.scout.commons.logger.ScoutLogManager; @@ -30,6 +31,21 @@ import org.osgi.framework.Bundle; * Configuration of input and output files */ public class SpecFileConfig { + /** + * Commandline parameter or SystemProperty (comma separated) for defining additional source plugins for copying + * mediawiki, image and config files. Source and binary plugins are supported. + * <p> + * Attention order matters for copying files: <br> + * First files from the additional plugins are copied in the same order as the plugins are provided here. Then files + * from the plugin returned by {@link #getBundle()} are copied. If different plugins contain files with the same name + * they are overwritten. + * <p> + * + * @param additionalSourcePlugins + * one or more bundle-symbolic-names + */ + // TODO ASA So far, there is no support for subdirectories. Would we need it? + private static final String ADDITIONAL_SOURCE_PLUGINS = "additionalSourcePlugins"; private static final String SPEC_OUT_DIR_NAME = "target" + File.separator + "spec"; private static final String SPEC_IN_DIR_NAME = "resources" + File.separator + "spec"; @@ -37,6 +53,7 @@ public class SpecFileConfig { private static final String MEDIAWIKI_DIR_NAME = "mediawiki"; private static final String LINKS_FILE_NAME = "links.properties"; + // TODO ASA configure output dir, remove m_bundle, change m_additionalSourcePlugins to m_sourcePlugin and explicitly configure all private String[] m_additionalSourcePlugins = new String[0]; private Bundle m_bundle; @@ -50,11 +67,36 @@ public class SpecFileConfig { if (product != null) { m_bundle = product.getDefiningBundle(); } + readAdditionalSourcePluginsFromConfig(); + } + + private void readAdditionalSourcePluginsFromConfig() { + String parameter = getConfigParameter(ADDITIONAL_SOURCE_PLUGINS); + m_additionalSourcePlugins = StringUtility.split(parameter, ","); + } + + /** + * Returns the configuration value for the given parameter that is either configured as + * command line argument or as system property. + * + * @param parameterName + * @return + */ + // TODO ASA copied form ScoutJUnitPluginTestExecutor --> move to Utility + private static String getConfigParameter(String parameterName) { + String commandLineArgumentName = "-" + parameterName + "="; + for (String arg : Platform.getCommandLineArgs()) { + if (arg != null && arg.startsWith(commandLineArgumentName)) { + return arg.substring(commandLineArgumentName.length()); + } + } + return System.getProperty(parameterName); } /** * The bundle property ({@link #getBundle()}) will be set to provided plugin. */ + // TODO ASA only used in tests; refactor: configure output dir instead of bundle public SpecFileConfig(String pluginName) { m_bundle = Platform.getBundle(pluginName); } @@ -85,6 +127,9 @@ public class SpecFileConfig { private static IScoutLogger LOG = ScoutLogManager.getLogger(SpecFileConfig.class); + /** + * @return all source bundles, ordered by priority: lowest priority first, highest last + */ public List<Bundle> getSourceBundles() { ArrayList<Bundle> arrayList = new ArrayList<Bundle>(); for (String bundleName : m_additionalSourcePlugins) { @@ -138,6 +183,10 @@ public class SpecFileConfig { return SPEC_IN_DIR_NAME + File.separator + MEDIAWIKI_DIR_NAME; } + public String getRelativeSourceDirPath() { + return SPEC_IN_DIR_NAME; + } + public String getRelativeImagesSourceDirPath() { return SPEC_IN_DIR_NAME + File.separator + IMAGES_DIR_NAME; } @@ -164,21 +213,4 @@ public class SpecFileConfig { return new File(getSpecDir(), LINKS_FILE_NAME); } - /** - * Define additional source plugins for copying mediawiki and image files. Source and binary plugins are supported. - * <p> - * Attention order matters for copying files: <br> - * First files from the additional plugins are copied in the same order as the plugins are provided here. Then files - * from the plugin returned by {@link #getBundle()} are copied. If different plugins contain files with the same name - * they are overwritten. - * <p> - * - * @param additionalSourcePlugins - * one or more bundle-symbolic-names - */ - // TODO ASA So far, there is no support for subdirectories. Would we need it? - public void setAdditionalSourcePlugins(String... additionalSourcePlugins) { - m_additionalSourcePlugins = additionalSourcePlugins; - } - } |