Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BZ-1051463 - Saving a rule file should not cause a Data Model Oracle …
…rebuild
- Loading branch information
Showing
15 changed files
with
785 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...-api/src/main/java/org/kie/workbench/common/services/shared/rulename/RuleNameService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2014 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.workbench.common.services.shared.rulename; | ||
|
||
import java.util.List; | ||
|
||
public interface RuleNameService { | ||
|
||
public List<String> getRuleNames(String packageName); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
...es-backend/src/main/java/org/kie/workbench/common/services/backend/rulename/MockPath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright 2014 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.workbench.common.services.backend.rulename; | ||
|
||
import java.io.File; | ||
import java.net.URI; | ||
import java.util.Iterator; | ||
|
||
import org.uberfire.java.nio.IOException; | ||
import org.uberfire.java.nio.file.ClosedWatchServiceException; | ||
import org.uberfire.java.nio.file.FileSystem; | ||
import org.uberfire.java.nio.file.InvalidPathException; | ||
import org.uberfire.java.nio.file.LinkOption; | ||
import org.uberfire.java.nio.file.Path; | ||
import org.uberfire.java.nio.file.WatchEvent; | ||
import org.uberfire.java.nio.file.WatchKey; | ||
import org.uberfire.java.nio.file.WatchService; | ||
|
||
public class MockPath implements Path { | ||
|
||
private final String fileName; | ||
private final FileSystem fileSystem; | ||
|
||
public MockPath(String fileName, FileSystem fileSystem) { | ||
this.fileName = fileName; | ||
this.fileSystem = fileSystem; | ||
} | ||
|
||
@Override public FileSystem getFileSystem() { | ||
return fileSystem; | ||
} | ||
|
||
@Override public boolean isAbsolute() { | ||
return false; | ||
} | ||
|
||
@Override public Path getRoot() { | ||
return null; | ||
} | ||
|
||
@Override public Path getFileName() { | ||
return this; | ||
} | ||
|
||
@Override public Path getParent() { | ||
return null; | ||
} | ||
|
||
@Override public int getNameCount() { | ||
return 0; | ||
} | ||
|
||
@Override public Path getName(int index) throws IllegalArgumentException { | ||
return null; | ||
} | ||
|
||
@Override public Path subpath(int beginIndex, int endIndex) throws IllegalArgumentException { | ||
return null; | ||
} | ||
|
||
@Override public boolean startsWith(Path other) { | ||
return false; | ||
} | ||
|
||
@Override public boolean startsWith(String other) throws InvalidPathException { | ||
return false; | ||
} | ||
|
||
@Override public boolean endsWith(Path other) { | ||
return false; | ||
} | ||
|
||
@Override public boolean endsWith(String other) throws InvalidPathException { | ||
return false; | ||
} | ||
|
||
@Override public Path normalize() { | ||
return null; | ||
} | ||
|
||
@Override public Path resolve(Path other) { | ||
return null; | ||
} | ||
|
||
@Override public Path resolve(String other) throws InvalidPathException { | ||
return null; | ||
} | ||
|
||
@Override public Path resolveSibling(Path other) { | ||
return null; | ||
} | ||
|
||
@Override public Path resolveSibling(String other) throws InvalidPathException { | ||
return null; | ||
} | ||
|
||
@Override public Path relativize(Path other) throws IllegalArgumentException { | ||
return null; | ||
} | ||
|
||
@Override public URI toUri() throws IOException, SecurityException { | ||
return URI.create("git://" + fileName); | ||
} | ||
|
||
@Override public Path toAbsolutePath() throws IOException, SecurityException { | ||
return null; | ||
} | ||
|
||
@Override public Path toRealPath(LinkOption... options) throws IOException, SecurityException { | ||
return null; | ||
} | ||
|
||
@Override public File toFile() throws UnsupportedOperationException { | ||
return null; | ||
} | ||
|
||
@Override public int compareTo(Path path) { | ||
return 0; | ||
} | ||
|
||
@Override public Iterator<Path> iterator() { | ||
return null; | ||
} | ||
|
||
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws UnsupportedOperationException, IllegalArgumentException, ClosedWatchServiceException, IOException, SecurityException { | ||
return null; | ||
} | ||
|
||
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws UnsupportedOperationException, IllegalArgumentException, ClosedWatchServiceException, IOException, SecurityException { | ||
return null; | ||
} | ||
|
||
@Override public String toString() { | ||
return fileName; | ||
} | ||
} |
152 changes: 152 additions & 0 deletions
152
...nd/src/main/java/org/kie/workbench/common/services/backend/rulename/RuleNameResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
* Copyright 2014 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.workbench.common.services.backend.rulename; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class RuleNameResolver { | ||
|
||
private ArrayList<String> ruleNames = new ArrayList<String>(); | ||
|
||
private String drl; | ||
|
||
private boolean currentRuleNameHasQuotes = false; | ||
|
||
public RuleNameResolver(String drl) { | ||
this.drl = drl; | ||
} | ||
|
||
public List<String> resolve() { | ||
|
||
// Strip comments | ||
while (drl.contains("//")) { | ||
int commentStart = drl.indexOf("//"); | ||
int endOfComment = drl.indexOf("\n", commentStart); | ||
if (endOfComment >= 0) { | ||
drl = drl.substring(0, commentStart) + drl.substring(endOfComment); | ||
} else { | ||
drl = drl.substring(0, commentStart); | ||
} | ||
} | ||
|
||
while (hasMultiLineComment()) { | ||
clearMultiLineComment(); | ||
} | ||
|
||
while (hasRule()) { | ||
String ruleLine = getNextRuleHeaderLine(); | ||
|
||
stripNameFromLine(ruleNames, ruleLine); | ||
|
||
drl = drl.substring(drl.indexOf(ruleLine) + ruleLine.length()); | ||
} | ||
|
||
return ruleNames; | ||
} | ||
|
||
private void clearMultiLineComment() { | ||
int startIndexOfTheComment = drl.indexOf("/*"); | ||
|
||
drl = drl.substring(0, startIndexOfTheComment) + drl.substring(getEndOfComment()); | ||
} | ||
|
||
private int getEndOfComment() { | ||
int endOfComment = drl.indexOf("*/") + "*/".length(); | ||
|
||
while (endOfNextComment(endOfComment) >= 0) { | ||
int endOfNextComment = endOfNextComment(endOfComment) + "*/".length(); | ||
|
||
String substring = drl.substring(endOfComment, endOfNextComment); | ||
if (endOfNextComment >= 0 && !hasMultiLineComment(substring)) { | ||
endOfComment = endOfNextComment; | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
return endOfComment; | ||
} | ||
|
||
private boolean hasMultiLineComment(String substring) { | ||
return substring.contains("*/") | ||
&& substring.contains("/*") | ||
&& substring.indexOf("/*") < substring.indexOf("*/"); | ||
} | ||
|
||
private int endOfNextComment(int endOfComment) { | ||
return drl.indexOf("*/", endOfComment); | ||
} | ||
|
||
private boolean hasMultiLineComment() { | ||
return drl.indexOf("/*") >= 0; | ||
} | ||
|
||
private String getNextRuleHeaderLine() { | ||
int beginIndex = getRuleIndex(); | ||
return drl.substring(beginIndex, drl.indexOf("\n", beginIndex)); | ||
} | ||
|
||
private int getRuleIndex() { | ||
int ruleIndex = drl.indexOf("rule"); | ||
|
||
int beginIndexWithQuotes = drl.indexOf("rule \""); | ||
|
||
if (ruleIndex >= beginIndexWithQuotes && beginIndexWithQuotes >= 0) { | ||
currentRuleNameHasQuotes = true; | ||
return beginIndexWithQuotes; | ||
} else { | ||
currentRuleNameHasQuotes = false; | ||
return ruleIndex; | ||
} | ||
} | ||
|
||
private boolean hasRule() { | ||
return getRuleIndex() >= 0; | ||
} | ||
|
||
private void stripNameFromLine(ArrayList<String> ruleNames, String ruleLine) { | ||
ruleLine = removeTheWorldRuleAndWhiteSpacesFromTheBeginning(ruleLine); | ||
|
||
int endIndex = getRuleNameEndIndex(ruleLine); | ||
if (endIndex >= 0) { | ||
ruleNames.add(ruleLine.substring(0, endIndex)); | ||
} else { | ||
ruleNames.add(ruleLine); | ||
} | ||
} | ||
|
||
private String removeTheWorldRuleAndWhiteSpacesFromTheBeginning(String ruleLine) { | ||
return ruleLine.substring(getRuleFrontBitLength()).trim(); | ||
} | ||
|
||
private int getRuleNameEndIndex(String ruleLine) { | ||
if (currentRuleNameHasQuotes) { | ||
return ruleLine.indexOf("\""); | ||
} else { | ||
return ruleLine.indexOf(" "); | ||
} | ||
} | ||
|
||
private int getRuleFrontBitLength() { | ||
if (currentRuleNameHasQuotes) { | ||
return "rule \"".length(); | ||
} else { | ||
return "rule".length(); | ||
} | ||
} | ||
} |
Oops, something went wrong.