mirror of
https://github.com/octoleo/plantuml.git
synced 2024-12-22 10:59:01 +00:00
fix: improve filelist support and nwdiag
This commit is contained in:
parent
793b78abc5
commit
b32500bb61
@ -1,4 +1,4 @@
|
|||||||
# Warning, "version" should be the same in gradle.properties and Version.java
|
# Warning, "version" should be the same in gradle.properties and Version.java
|
||||||
# Any idea anyone how to magically synchronize those :-) ?
|
# Any idea anyone how to magically synchronize those :-) ?
|
||||||
version = 1.2023.9beta3
|
version = 1.2023.9beta4
|
||||||
org.gradle.workers.max = 3
|
org.gradle.workers.max = 3
|
@ -57,15 +57,15 @@ public class AParentFolderRegular implements AParentFolder {
|
|||||||
final SFile filecurrent;
|
final SFile filecurrent;
|
||||||
// Log.info("AParentFolderRegular::looking for " + nameOrPath);
|
// Log.info("AParentFolderRegular::looking for " + nameOrPath);
|
||||||
// Log.info("AParentFolderRegular::dir = " + dir);
|
// Log.info("AParentFolderRegular::dir = " + dir);
|
||||||
if (dir == null) {
|
if (dir == null)
|
||||||
filecurrent = new SFile(nameOrPath);
|
filecurrent = new SFile(nameOrPath);
|
||||||
} else {
|
else
|
||||||
filecurrent = dir.getAbsoluteFile().file(nameOrPath);
|
filecurrent = dir.getAbsoluteFile().file(nameOrPath);
|
||||||
}
|
|
||||||
// Log.info("AParentFolderRegular::Filecurrent " + filecurrent);
|
// Log.info("AParentFolderRegular::Filecurrent " + filecurrent);
|
||||||
if (filecurrent.exists()) {
|
if (filecurrent.exists())
|
||||||
return new AFileRegular(filecurrent.getCanonicalFile());
|
return new AFileRegular(filecurrent.getCanonicalFile());
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
111
src/net/sourceforge/plantuml/filesdiagram/FilesEntry.java
Normal file
111
src/net/sourceforge/plantuml/filesdiagram/FilesEntry.java
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
/* ========================================================================
|
||||||
|
* PlantUML : a free UML diagram generator
|
||||||
|
* ========================================================================
|
||||||
|
*
|
||||||
|
* (C) Copyright 2009-2024, Arnaud Roques
|
||||||
|
*
|
||||||
|
* Project Info: https://plantuml.com
|
||||||
|
*
|
||||||
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
|
*
|
||||||
|
* https://plantuml.com/patreon (only 1$ per month!)
|
||||||
|
* https://plantuml.com/paypal
|
||||||
|
*
|
||||||
|
* This file is part of PlantUML.
|
||||||
|
*
|
||||||
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* PlantUML distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Original Author: Arnaud Roques
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.sourceforge.plantuml.filesdiagram;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.klimt.UTranslate;
|
||||||
|
import net.sourceforge.plantuml.klimt.creole.Display;
|
||||||
|
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
|
||||||
|
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
|
||||||
|
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
|
||||||
|
import net.sourceforge.plantuml.klimt.shape.TextBlock;
|
||||||
|
import net.sourceforge.plantuml.style.ISkinParam;
|
||||||
|
|
||||||
|
public class FilesEntry implements Iterable<FilesEntry> {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private FilesType type;
|
||||||
|
private List<FilesEntry> children = new ArrayList<>();
|
||||||
|
|
||||||
|
public FilesEntry(String name, FilesType type) {
|
||||||
|
this.name = name;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilesEntry addRawEntry(String raw) {
|
||||||
|
final int x = raw.indexOf('/');
|
||||||
|
if (x == -1) {
|
||||||
|
final FilesEntry result = new FilesEntry(raw, FilesType.DATA);
|
||||||
|
children.add(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
final FilesEntry folder = getOrCreateFolder(raw.substring(0, x));
|
||||||
|
final String remain = raw.substring(x + 1);
|
||||||
|
if (remain.length() == 0)
|
||||||
|
return folder;
|
||||||
|
return folder.addRawEntry(remain);
|
||||||
|
}
|
||||||
|
|
||||||
|
private FilesEntry getOrCreateFolder(String folderName) {
|
||||||
|
for (FilesEntry child : children)
|
||||||
|
if (child.type == FilesType.FOLDER && child.getName().equals(folderName))
|
||||||
|
return child;
|
||||||
|
|
||||||
|
final FilesEntry result = new FilesEntry(folderName, FilesType.FOLDER);
|
||||||
|
children.add(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<FilesEntry> iterator() {
|
||||||
|
return Collections.unmodifiableCollection(children).iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmoticon() {
|
||||||
|
if (type == FilesType.FOLDER)
|
||||||
|
return "<:1f4c2:>";
|
||||||
|
// return "<:1f4c1:>";
|
||||||
|
return "<:1f4c4:>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public UGraphic drawAndMove(UGraphic ug, FontConfiguration fontConfiguration, ISkinParam skinParam, double deltax) {
|
||||||
|
final Display display = Display.getWithNewlines(getEmoticon() + getName());
|
||||||
|
TextBlock result = display.create(fontConfiguration, HorizontalAlignment.LEFT, skinParam);
|
||||||
|
result.drawU(ug.apply(UTranslate.dx(deltax)));
|
||||||
|
ug = ug.apply(UTranslate.dy(result.calculateDimension(ug.getStringBounder()).getHeight() + 2));
|
||||||
|
for (FilesEntry child : children)
|
||||||
|
ug = child.drawAndMove(ug, fontConfiguration, skinParam, deltax + 21);
|
||||||
|
return ug;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -34,26 +34,19 @@
|
|||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.filesdiagram;
|
package net.sourceforge.plantuml.filesdiagram;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.sourceforge.plantuml.klimt.UTranslate;
|
|
||||||
import net.sourceforge.plantuml.klimt.creole.Display;
|
|
||||||
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
|
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
|
||||||
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
|
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
|
||||||
import net.sourceforge.plantuml.klimt.font.StringBounder;
|
import net.sourceforge.plantuml.klimt.font.StringBounder;
|
||||||
import net.sourceforge.plantuml.klimt.font.UFont;
|
import net.sourceforge.plantuml.klimt.font.UFont;
|
||||||
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
|
|
||||||
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
|
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
|
||||||
import net.sourceforge.plantuml.klimt.shape.AbstractTextBlock;
|
import net.sourceforge.plantuml.klimt.shape.AbstractTextBlock;
|
||||||
import net.sourceforge.plantuml.klimt.shape.TextBlock;
|
|
||||||
import net.sourceforge.plantuml.style.ISkinParam;
|
import net.sourceforge.plantuml.style.ISkinParam;
|
||||||
|
|
||||||
public class FilesListing extends AbstractTextBlock {
|
public class FilesListing extends AbstractTextBlock {
|
||||||
|
|
||||||
private final ISkinParam skinParam;
|
private final ISkinParam skinParam;
|
||||||
private final FontConfiguration fontConfiguration = FontConfiguration.blackBlueTrue(UFont.courier(14));
|
private final FontConfiguration fontConfiguration = FontConfiguration.blackBlueTrue(UFont.courier(14));
|
||||||
private final List<String> tmp = new ArrayList<>();
|
private final FilesEntry root = new FilesEntry("", FilesType.FOLDER);
|
||||||
|
|
||||||
public FilesListing(ISkinParam skinParam) {
|
public FilesListing(ISkinParam skinParam) {
|
||||||
this.skinParam = skinParam;
|
this.skinParam = skinParam;
|
||||||
@ -66,18 +59,13 @@ public class FilesListing extends AbstractTextBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawU(UGraphic ug) {
|
public void drawU(UGraphic ug) {
|
||||||
for (String s : tmp) {
|
for (FilesEntry ent : root)
|
||||||
final Display display = Display.getWithNewlines("<:1f4c4:>" + s);
|
ug = ent.drawAndMove(ug, fontConfiguration, skinParam, 0);
|
||||||
TextBlock result = display.create(fontConfiguration, HorizontalAlignment.LEFT, skinParam);
|
|
||||||
result.drawU(ug);
|
|
||||||
ug = ug.apply(UTranslate.dy(result.calculateDimension(ug.getStringBounder()).getHeight()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(String line) {
|
public void add(String line) {
|
||||||
if (line.startsWith("/"))
|
if (line.startsWith("/"))
|
||||||
tmp.add(line.substring(1));
|
root.addRawEntry(line.substring(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
40
src/net/sourceforge/plantuml/filesdiagram/FilesType.java
Normal file
40
src/net/sourceforge/plantuml/filesdiagram/FilesType.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* ========================================================================
|
||||||
|
* PlantUML : a free UML diagram generator
|
||||||
|
* ========================================================================
|
||||||
|
*
|
||||||
|
* (C) Copyright 2009-2024, Arnaud Roques
|
||||||
|
*
|
||||||
|
* Project Info: https://plantuml.com
|
||||||
|
*
|
||||||
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
|
*
|
||||||
|
* https://plantuml.com/patreon (only 1$ per month!)
|
||||||
|
* https://plantuml.com/paypal
|
||||||
|
*
|
||||||
|
* This file is part of PlantUML.
|
||||||
|
*
|
||||||
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* PlantUML distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Original Author: Arnaud Roques
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.sourceforge.plantuml.filesdiagram;
|
||||||
|
|
||||||
|
public enum FilesType {
|
||||||
|
FOLDER, DATA;
|
||||||
|
|
||||||
|
}
|
@ -66,26 +66,26 @@ public class SpriteColor implements Sprite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setGray(int x, int y, int level) {
|
public void setGray(int x, int y, int level) {
|
||||||
if (x < 0 || x >= width) {
|
if (x < 0 || x >= width)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (y < 0 || y >= height) {
|
if (y < 0 || y >= height)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (level < 0 || level >= 16) {
|
if (level < 0 || level >= 16)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
|
||||||
gray[y][x] = level;
|
gray[y][x] = level;
|
||||||
color[y][x] = -1;
|
color[y][x] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(int x, int y, int col) {
|
public void setColor(int x, int y, int col) {
|
||||||
if (x < 0 || x >= width) {
|
if (x < 0 || x >= width)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (y < 0 || y >= height) {
|
if (y < 0 || y >= height)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
gray[y][x] = -1;
|
gray[y][x] = -1;
|
||||||
color[y][x] = col;
|
color[y][x] = col;
|
||||||
}
|
}
|
||||||
@ -99,14 +99,14 @@ public class SpriteColor implements Sprite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public UImage toUImage(ColorMapper colorMapper, HColor backcolor, HColor forecolor) {
|
public UImage toUImage(ColorMapper colorMapper, HColor backcolor, HColor forecolor) {
|
||||||
final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
|
|
||||||
if (backcolor == null) {
|
if (backcolor == null)
|
||||||
backcolor = HColors.WHITE;
|
backcolor = HColors.WHITE;
|
||||||
}
|
|
||||||
if (forecolor == null) {
|
if (forecolor == null)
|
||||||
forecolor = HColors.BLACK;
|
forecolor = HColors.BLACK;
|
||||||
}
|
|
||||||
final HColorGradient gradient = HColors.gradient(backcolor, forecolor, '\0');
|
final HColorGradient gradient = HColors.gradient(backcolor, forecolor, '\0');
|
||||||
for (int col = 0; col < width; col++) {
|
for (int col = 0; col < width; col++) {
|
||||||
for (int line = 0; line < height; line++) {
|
for (int line = 0; line < height; line++) {
|
||||||
|
@ -150,11 +150,27 @@ public class NwDiagram extends UmlDiagram {
|
|||||||
for (NStackable element : stack)
|
for (NStackable element : stack)
|
||||||
if (element instanceof Network)
|
if (element instanceof Network)
|
||||||
return CommandExecutionResult.error("Cannot nest network");
|
return CommandExecutionResult.error("Cannot nest network");
|
||||||
|
|
||||||
|
if (networks.size() == 0 && groups.size() == 0)
|
||||||
|
eventuallyConnectAllStandaloneServersToHiddenNetwork();
|
||||||
|
|
||||||
final Network network = createNetwork(name);
|
final Network network = createNetwork(name);
|
||||||
stack.add(0, network);
|
stack.add(0, network);
|
||||||
return CommandExecutionResult.ok();
|
return CommandExecutionResult.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void eventuallyConnectAllStandaloneServersToHiddenNetwork() {
|
||||||
|
Network first = null;
|
||||||
|
for (NServer server : servers.values())
|
||||||
|
if (server.isAlone()) {
|
||||||
|
if (first == null) {
|
||||||
|
first = createNetwork("");
|
||||||
|
first.goInvisible();
|
||||||
|
}
|
||||||
|
server.connectMeIfAlone(first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public CommandExecutionResult closeSomething() {
|
public CommandExecutionResult closeSomething() {
|
||||||
if (initDone == false)
|
if (initDone == false)
|
||||||
return errorNoInit();
|
return errorNoInit();
|
||||||
|
@ -112,6 +112,8 @@ public class NServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void learnThisAddress(String address) {
|
public void learnThisAddress(String address) {
|
||||||
|
if (address == null)
|
||||||
|
address = "";
|
||||||
for (Entry<Network, String> ent : connections.entrySet()) {
|
for (Entry<Network, String> ent : connections.entrySet()) {
|
||||||
if (ent.getValue().length() == 0) {
|
if (ent.getValue().length() == 0) {
|
||||||
connections.put(ent.getKey(), address);
|
connections.put(ent.getKey(), address);
|
||||||
|
@ -250,7 +250,7 @@ public class SURL {
|
|||||||
/**
|
/**
|
||||||
* Regex to remove the UserInfo part from a URL.
|
* Regex to remove the UserInfo part from a URL.
|
||||||
*/
|
*/
|
||||||
private static final Pattern PATTERN_USERINFO = Pattern.compile("(^https?://)([-_0-9a-zA-Z]+@)([^@]*)");
|
private static final Pattern PATTERN_USERINFO = Pattern.compile("(^https?://)([-_0-9a-zA-Z]+@)([^@]*)$");
|
||||||
|
|
||||||
private static final ExecutorService EXE = Executors.newCachedThreadPool(new ThreadFactory() {
|
private static final ExecutorService EXE = Executors.newCachedThreadPool(new ThreadFactory() {
|
||||||
public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
@ -292,6 +292,9 @@ public class SURL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean forbiddenURL(String full) {
|
private boolean forbiddenURL(String full) {
|
||||||
|
// Thanks to Agasthya Kasturi
|
||||||
|
if (full.contains("@"))
|
||||||
|
return true;
|
||||||
if (full.startsWith("https://") == false && full.startsWith("http://") == false)
|
if (full.startsWith("https://") == false && full.startsWith("http://") == false)
|
||||||
return true;
|
return true;
|
||||||
if (full.matches("^https?://[-#.0-9:\\[\\]+]+/.*"))
|
if (full.matches("^https?://[-#.0-9:\\[\\]+]+/.*"))
|
||||||
@ -305,6 +308,9 @@ public class SURL {
|
|||||||
|
|
||||||
private boolean isInUrlAllowList() {
|
private boolean isInUrlAllowList() {
|
||||||
final String full = cleanPath(internal.toString());
|
final String full = cleanPath(internal.toString());
|
||||||
|
// Thanks to Agasthya Kasturi
|
||||||
|
if (full.contains("@"))
|
||||||
|
return false;
|
||||||
for (String allow : getUrlAllowList())
|
for (String allow : getUrlAllowList())
|
||||||
if (full.startsWith(cleanPath(allow)))
|
if (full.startsWith(cleanPath(allow)))
|
||||||
return true;
|
return true;
|
||||||
|
@ -60,9 +60,9 @@ public class TFunctionImpl implements TFunction {
|
|||||||
public TFunctionImpl(String functionName, List<TFunctionArgument> args, boolean unquoted,
|
public TFunctionImpl(String functionName, List<TFunctionArgument> args, boolean unquoted,
|
||||||
TFunctionType functionType) {
|
TFunctionType functionType) {
|
||||||
final Set<String> names = new HashSet<>();
|
final Set<String> names = new HashSet<>();
|
||||||
for (TFunctionArgument tmp : args) {
|
for (TFunctionArgument tmp : args)
|
||||||
names.add(tmp.getName());
|
names.add(tmp.getName());
|
||||||
}
|
|
||||||
this.signature = new TFunctionSignature(functionName, args.size(), names);
|
this.signature = new TFunctionSignature(functionName, args.size(), names);
|
||||||
this.args = args;
|
this.args = args;
|
||||||
this.unquoted = unquoted;
|
this.unquoted = unquoted;
|
||||||
@ -70,27 +70,26 @@ public class TFunctionImpl implements TFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canCover(int nbArg, Set<String> namedArguments) {
|
public boolean canCover(int nbArg, Set<String> namedArguments) {
|
||||||
for (String n : namedArguments) {
|
for (String n : namedArguments)
|
||||||
if (signature.getNamedArguments().contains(n) == false) {
|
if (signature.getNamedArguments().contains(n) == false)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
if (nbArg > args.size())
|
||||||
if (nbArg > args.size()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
assert nbArg <= args.size();
|
assert nbArg <= args.size();
|
||||||
int neededArgument = 0;
|
int neededArgument = 0;
|
||||||
for (TFunctionArgument arg : args) {
|
for (TFunctionArgument arg : args) {
|
||||||
if (namedArguments.contains(arg.getName())) {
|
if (namedArguments.contains(arg.getName()))
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if (arg.getOptionalDefaultValue() == null) {
|
if (arg.getOptionalDefaultValue() == null)
|
||||||
neededArgument++;
|
neededArgument++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (nbArg < neededArgument) {
|
if (nbArg < neededArgument)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
assert nbArg >= neededArgument;
|
assert nbArg >= neededArgument;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -108,9 +107,9 @@ public class TFunctionImpl implements TFunction {
|
|||||||
} else {
|
} else {
|
||||||
value = arg.getOptionalDefaultValue();
|
value = arg.getOptionalDefaultValue();
|
||||||
}
|
}
|
||||||
if (value == null) {
|
if (value == null)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
|
||||||
result.put(arg.getName(), value);
|
result.put(arg.getName(), value);
|
||||||
}
|
}
|
||||||
return memory.forkFromGlobal(result);
|
return memory.forkFromGlobal(result);
|
||||||
@ -125,11 +124,9 @@ public class TFunctionImpl implements TFunction {
|
|||||||
body.add(s);
|
body.add(s);
|
||||||
if (s.getType() == TLineType.RETURN) {
|
if (s.getType() == TLineType.RETURN) {
|
||||||
this.containsReturn = true;
|
this.containsReturn = true;
|
||||||
if (functionType == TFunctionType.PROCEDURE) {
|
if (functionType == TFunctionType.PROCEDURE)
|
||||||
throw EaterExceptionLocated
|
throw EaterExceptionLocated
|
||||||
.located("A procedure cannot have !return directive. Declare it as a function instead ?", s);
|
.located("A procedure cannot have !return directive. Declare it as a function instead ?", s);
|
||||||
// this.functionType = TFunctionType.RETURN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,39 +144,39 @@ public class TFunctionImpl implements TFunction {
|
|||||||
|
|
||||||
public void executeProcedureInternal(TContext context, TMemory memory, List<TValue> args, Map<String, TValue> named)
|
public void executeProcedureInternal(TContext context, TMemory memory, List<TValue> args, Map<String, TValue> named)
|
||||||
throws EaterException, EaterExceptionLocated {
|
throws EaterException, EaterExceptionLocated {
|
||||||
if (functionType != TFunctionType.PROCEDURE && functionType != TFunctionType.LEGACY_DEFINELONG) {
|
if (functionType != TFunctionType.PROCEDURE && functionType != TFunctionType.LEGACY_DEFINELONG)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
|
||||||
final TMemory copy = getNewMemory(memory, args, named);
|
final TMemory copy = getNewMemory(memory, args, named);
|
||||||
context.executeLines(copy, body, TFunctionType.PROCEDURE, false);
|
context.executeLines(copy, body, TFunctionType.PROCEDURE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> args,
|
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> args,
|
||||||
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
|
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
|
||||||
if (functionType == TFunctionType.LEGACY_DEFINE) {
|
if (functionType == TFunctionType.LEGACY_DEFINE)
|
||||||
return executeReturnLegacyDefine(location, context, memory, args);
|
return executeReturnLegacyDefine(location, context, memory, args);
|
||||||
}
|
|
||||||
if (functionType != TFunctionType.RETURN_FUNCTION) {
|
if (functionType != TFunctionType.RETURN_FUNCTION)
|
||||||
throw EaterException.unlocated("Illegal call here. Is there a return directive in your function?");
|
throw EaterException.unlocated("Illegal call here. Is there a return directive in your function?");
|
||||||
}
|
|
||||||
final TMemory copy = getNewMemory(memory, args, named);
|
final TMemory copy = getNewMemory(memory, args, named);
|
||||||
final TValue result = context.executeLines(copy, body, TFunctionType.RETURN_FUNCTION, true);
|
final TValue result = context.executeLines(copy, body, TFunctionType.RETURN_FUNCTION, true);
|
||||||
if (result == null) {
|
if (result == null)
|
||||||
throw EaterException.unlocated("No return directive found in your function");
|
throw EaterException.unlocated("No return directive found in your function");
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TValue executeReturnLegacyDefine(LineLocation location, TContext context, TMemory memory, List<TValue> args)
|
private TValue executeReturnLegacyDefine(LineLocation location, TContext context, TMemory memory, List<TValue> args)
|
||||||
throws EaterException, EaterExceptionLocated {
|
throws EaterException, EaterExceptionLocated {
|
||||||
if (legacyDefinition == null) {
|
if (legacyDefinition == null)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
|
||||||
final TMemory copy = getNewMemory(memory, args, Collections.<String, TValue>emptyMap());
|
final TMemory copy = getNewMemory(memory, args, Collections.<String, TValue>emptyMap());
|
||||||
final String tmp = context.applyFunctionsAndVariables(copy, location, legacyDefinition);
|
final String tmp = context.applyFunctionsAndVariables(copy, location, legacyDefinition);
|
||||||
if (tmp == null) {
|
if (tmp == null)
|
||||||
return TValue.fromString("");
|
return TValue.fromString("");
|
||||||
}
|
|
||||||
return TValue.fromString(tmp);
|
return TValue.fromString(tmp);
|
||||||
// eaterReturn.execute(context, copy);
|
// eaterReturn.execute(context, copy);
|
||||||
// // System.err.println("s3=" + eaterReturn.getValue2());
|
// // System.err.println("s3=" + eaterReturn.getValue2());
|
||||||
@ -211,9 +208,9 @@ public class TFunctionImpl implements TFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void finalizeEnddefinelong() {
|
public void finalizeEnddefinelong() {
|
||||||
if (functionType != TFunctionType.LEGACY_DEFINELONG) {
|
if (functionType != TFunctionType.LEGACY_DEFINELONG)
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
|
||||||
if (body.size() == 1) {
|
if (body.size() == 1) {
|
||||||
this.functionType = TFunctionType.LEGACY_DEFINE;
|
this.functionType = TFunctionType.LEGACY_DEFINE;
|
||||||
this.legacyDefinition = body.get(0).getString();
|
this.legacyDefinition = body.get(0).getString();
|
||||||
|
@ -108,27 +108,27 @@ public class LicenseInfo {
|
|||||||
|
|
||||||
public static synchronized LicenseInfo retrieveNamedSlow() {
|
public static synchronized LicenseInfo retrieveNamedSlow() {
|
||||||
cache = LicenseInfo.NONE;
|
cache = LicenseInfo.NONE;
|
||||||
if (OptionFlags.ALLOW_INCLUDE == false) {
|
if (OptionFlags.ALLOW_INCLUDE == false)
|
||||||
return cache;
|
return cache;
|
||||||
}
|
|
||||||
final String key = prefs.get("license", "");
|
final String key = prefs.get("license", "");
|
||||||
if (key.length() > 0) {
|
if (key.length() > 0) {
|
||||||
cache = setIfValid(retrieveNamed(key), cache);
|
cache = setIfValid(retrieveNamed(key), cache);
|
||||||
if (cache.isValid()) {
|
if (cache.isValid())
|
||||||
return cache;
|
return cache;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (SFile f : fileCandidates()) {
|
for (SFile f : fileCandidates()) {
|
||||||
try {
|
try {
|
||||||
if (f.exists() && f.canRead()) {
|
if (f.exists() && f.canRead()) {
|
||||||
final LicenseInfo result = retrieve(f);
|
final LicenseInfo result = retrieve(f);
|
||||||
if (result == null) {
|
if (result == null)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
cache = setIfValid(result, cache);
|
cache = setIfValid(result, cache);
|
||||||
if (cache.isValid()) {
|
if (cache.isValid())
|
||||||
return cache;
|
return cache;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.info("Error " + e);
|
Log.info("Error " + e);
|
||||||
@ -157,13 +157,13 @@ public class LicenseInfo {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final byte[] s1 = PLSSignature.retrieveDistributorImageSignature();
|
final byte[] s1 = PLSSignature.retrieveDistributorImageSignature();
|
||||||
if (SignatureUtils.toHexString(s1).equals(SignatureUtils.toHexString(licenseInfo.sha)) == false) {
|
if (SignatureUtils.toHexString(s1).equals(SignatureUtils.toHexString(licenseInfo.sha)) == false)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
final InputStream dis = PSystemVersion.class.getResourceAsStream("/distributor.png");
|
final InputStream dis = PSystemVersion.class.getResourceAsStream("/distributor.png");
|
||||||
if (dis == null) {
|
if (dis == null)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
final BufferedImage result = SImageIO.read(dis);
|
final BufferedImage result = SImageIO.read(dis);
|
||||||
return result;
|
return result;
|
||||||
@ -178,9 +178,9 @@ public class LicenseInfo {
|
|||||||
|
|
||||||
public static LicenseInfo retrieveDistributor() {
|
public static LicenseInfo retrieveDistributor() {
|
||||||
final InputStream dis = PSystemVersion.class.getResourceAsStream("/distributor.txt");
|
final InputStream dis = PSystemVersion.class.getResourceAsStream("/distributor.txt");
|
||||||
if (dis == null) {
|
if (dis == null)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
final BufferedReader br = new BufferedReader(new InputStreamReader(dis));
|
final BufferedReader br = new BufferedReader(new InputStreamReader(dis));
|
||||||
final String licenseString = br.readLine();
|
final String licenseString = br.readLine();
|
||||||
@ -188,11 +188,10 @@ public class LicenseInfo {
|
|||||||
final LicenseInfo result = PLSSignature.retrieveDistributor(licenseString);
|
final LicenseInfo result = PLSSignature.retrieveDistributor(licenseString);
|
||||||
final Throwable creationPoint = new Throwable();
|
final Throwable creationPoint = new Throwable();
|
||||||
creationPoint.fillInStackTrace();
|
creationPoint.fillInStackTrace();
|
||||||
for (StackTraceElement ste : creationPoint.getStackTrace()) {
|
for (StackTraceElement ste : creationPoint.getStackTrace())
|
||||||
if (ste.toString().contains(result.context)) {
|
if (ste.toString().contains(result.context))
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logme.error(e);
|
Logme.error(e);
|
||||||
@ -208,34 +207,34 @@ public class LicenseInfo {
|
|||||||
if (s == null)
|
if (s == null)
|
||||||
continue;
|
continue;
|
||||||
SFile dir = new SFile(s);
|
SFile dir = new SFile(s);
|
||||||
if (dir.isFile()) {
|
if (dir.isFile())
|
||||||
dir = dir.getParentFile();
|
dir = dir.getParentFile();
|
||||||
}
|
|
||||||
if (dir != null && dir.isDirectory()) {
|
if (dir != null && dir.isDirectory())
|
||||||
result.add(dir.file("license.txt"));
|
result.add(dir.file("license.txt"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LicenseInfo setIfValid(LicenseInfo value, LicenseInfo def) {
|
private static LicenseInfo setIfValid(LicenseInfo value, LicenseInfo def) {
|
||||||
if (value.isValid() || def.isNone()) {
|
if (value.isValid() || def.isNone())
|
||||||
return value;
|
return value;
|
||||||
}
|
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LicenseInfo retrieve(SFile f) throws IOException {
|
private static LicenseInfo retrieve(SFile f) throws IOException {
|
||||||
final BufferedReader br = f.openBufferedReader();
|
final BufferedReader br = f.openBufferedReader();
|
||||||
if (br == null) {
|
if (br == null)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
final String s = br.readLine();
|
final String s = br.readLine();
|
||||||
final LicenseInfo result = retrieveNamed(s);
|
final LicenseInfo result = retrieveNamed(s);
|
||||||
if (result != null) {
|
if (result != null)
|
||||||
Log.info("Reading license from " + f.getAbsolutePath());
|
Log.info("Reading license from " + f.getAbsolutePath());
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
} finally {
|
} finally {
|
||||||
br.close();
|
br.close();
|
||||||
|
@ -46,7 +46,7 @@ public class Version {
|
|||||||
|
|
||||||
// Warning, "version" should be the same in gradle.properties and Version.java
|
// Warning, "version" should be the same in gradle.properties and Version.java
|
||||||
// Any idea anyone how to magically synchronize those :-) ?
|
// Any idea anyone how to magically synchronize those :-) ?
|
||||||
private static final String version = "1.2023.9beta3";
|
private static final String version = "1.2023.9beta4";
|
||||||
|
|
||||||
public static String versionString() {
|
public static String versionString() {
|
||||||
return version;
|
return version;
|
||||||
|
Loading…
Reference in New Issue
Block a user