Please support including files from same directory in NetBeans

+1 vote
asked Jun 11, 2016 in Closed feature request by anonymous

PlantUML-NB uses SourceStringReader when converting .puml file to SVG for display in NetBeans.

SourceStringReader uses BlockUmlBuilder internally, which accepts a File newCurrentDir parameter, but SourceStringReader doesn't have a constructor to allow passing in this parameter.

So currently, the include directive doesn't work in NetBeans because without a current directory defined, PlantUML ends up looking in C:\Program Files\NetBeans 8.1 for the file to include, and of course it's not there because the file is in my project source directory.

Please add these constructors to SourceStringReader:

public SourceStringReader(String source, File newCurrentDir) {

this(new Defines(), source, "UTF-8", Collections.<String> emptyList(), newCurrentDir);

}

        

public SourceStringReader(Defines defines, String source, String charset, List<String> config, File newCurrentDir) {

// WARNING GLOBAL LOCK HERE

synchronized (SourceStringReader.class) {

try {

final BlockUmlBuilder builder = new BlockUmlBuilder(config, charset, defines, new StringReader(source), newCurrentDir, null);

this.blocks = builder.getBlockUmls();

} catch (IOException e) {

Log.error("error " + e);

throw new IllegalStateException(e);

}

}

}

Then, PUMLGenerator in PlantUML-NB can be modified like this:

SourceStringReader reader = new SourceStringReader(inputFile.asText(), FileUtil.toFile(inputFile).getParentFile());

And this fixes the issue, so the !include directive works in NetBeans by looking in directory of the file being processed.

1 Answer

0 votes
answered Jun 11, 2016 by plantuml (295,000 points)
selected Jul 7, 2018 by Anthony-Gaudino
 
Best answer

Thanks for the suggestion, and sorry that the API is far from perfect...

You can download the last beta https://dl.dropboxusercontent.com/u/13064071/plantuml.jar that now has the expected constructor. We did it slightly differently, to avoid code duplication, but the result is the same.

So you now have the following constructors:

    public SourceStringReader(String source, File newCurrentDir) {
        this(new Defines(), source, "UTF-8", Collections.<String> emptyList(), newCurrentDir);
    }

    public SourceStringReader(Defines defines, String source, String charset, List<String> config) {
        this(defines, source, charset, config, null);
    }

    public SourceStringReader(Defines defines, String source, String charset, List<String> config, File newCurrentDir) {
        // WARNING GLOBAL LOCK HERE
        synchronized (SourceStringReader.class) {
            try {
                final BlockUmlBuilder builder = new BlockUmlBuilder(config, charset, defines, new StringReader(source),
                        newCurrentDir, null);
                this.blocks = builder.getBlockUmls();
            } catch (IOException e) {
                Log.error("error " + e);
                throw new IllegalStateException(e);
            }
        }
    }

Tell us if it's not ok for you. This will be integrated in next official release.

...