diff --git a/build.gradle b/build.gradle index fddcb8d..25ff73c 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,15 @@ repositories { } } +// Include the generated files in the source set +sourceSets { + main { + java { + srcDirs("src/main/gen") + } + } +} + apply plugin: 'idea' apply plugin: 'org.jetbrains.intellij' apply plugin: 'java' diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/lexer/RequirementsLexer.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/lexer/RequirementsLexer.java new file mode 100644 index 0000000..bc1c814 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/lexer/RequirementsLexer.java @@ -0,0 +1,691 @@ +// Generated by JFlex 1.9.1 http://jflex.de/ (tweaked for IntelliJ platform) +// source: Requirements.flex + +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.lexer; + +import com.intellij.lexer.FlexLexer; +import com.intellij.psi.tree.IElementType; + +import static com.intellij.psi.TokenType.BAD_CHARACTER; +import static com.intellij.psi.TokenType.WHITE_SPACE; +import static org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.RequirementsTypes.*; + + +public class RequirementsLexer implements FlexLexer { + + /** This character denotes the end of file */ + public static final int YYEOF = -1; + + /** initial size of the lookahead buffer */ + private static final int ZZ_BUFFERSIZE = 16384; + + /** lexical states */ + public static final int YYINITIAL = 0; + public static final int REQ = 2; + public static final int REQ_OTHER = 4; + public static final int URI_SPEC = 6; + public static final int OTHER_SPEC = 8; + public static final int HANDLE_VERSION = 10; + + /** + * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l + * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l + * at the beginning of a line + * l is of the form l = 2*k, k a non negative integer + */ + private static final int ZZ_LEXSTATE[] = { + 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 + }; + + /** + * Top-level table for translating characters to character classes + */ + private static final int [] ZZ_CMAP_TOP = zzUnpackcmap_top(); + + private static final String ZZ_CMAP_TOP_PACKED_0 = + "\1\0\25\u0100\1\u0200\11\u0100\1\u0300\17\u0100\1\u0400\247\u0100"+ + "\10\u0500\u1020\u0100"; + + private static int [] zzUnpackcmap_top() { + int [] result = new int[4352]; + int offset = 0; + offset = zzUnpackcmap_top(ZZ_CMAP_TOP_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackcmap_top(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do result[j++] = value; while (--count > 0); + } + return j; + } + + + /** + * Second-level tables for translating characters to character classes + */ + private static final int [] ZZ_CMAP_BLOCKS = zzUnpackcmap_blocks(); + + private static final String ZZ_CMAP_BLOCKS_PACKED_0 = + "\11\0\1\1\1\2\2\3\1\2\22\0\1\1\1\4"+ + "\1\0\1\5\4\0\1\6\1\7\1\10\1\11\1\12"+ + "\1\13\1\14\1\15\12\16\1\17\1\20\1\21\1\22"+ + "\1\21\1\0\1\23\32\16\1\24\1\25\1\26\1\0"+ + "\1\27\1\0\32\16\1\0\1\30\1\0\1\31\6\0"+ + "\1\3\32\0\1\1\u01df\0\1\1\177\0\13\1\35\0"+ + "\2\3\5\0\1\1\57\0\1\1\240\0\1\1\377\0"+ + "\u0100\32"; + + private static int [] zzUnpackcmap_blocks() { + int [] result = new int[1536]; + int offset = 0; + offset = zzUnpackcmap_blocks(ZZ_CMAP_BLOCKS_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackcmap_blocks(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do result[j++] = value; while (--count > 0); + } + return j; + } + + /** + * Translates DFA states to action switch labels. + */ + private static final int [] ZZ_ACTION = zzUnpackAction(); + + private static final String ZZ_ACTION_PACKED_0 = + "\6\0\1\1\1\2\1\3\1\4\1\5\1\6\1\7"+ + "\1\2\1\1\1\10\1\11\1\12\1\13\1\1\1\14"+ + "\1\15\1\16\1\1\1\17\1\20\1\21\1\22\1\23"+ + "\1\24\1\25\1\26\1\0\1\27\1\30\1\16\1\0"; + + private static int [] zzUnpackAction() { + int [] result = new int[37]; + int offset = 0; + offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackAction(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do result[j++] = value; while (--count > 0); + } + return j; + } + + + /** + * Translates a state to a row index in the transition table + */ + private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); + + private static final String ZZ_ROWMAP_PACKED_0 = + "\0\0\0\33\0\66\0\121\0\154\0\207\0\242\0\275"+ + "\0\242\0\330\0\242\0\363\0\u010e\0\u0129\0\u0144\0\242"+ + "\0\242\0\242\0\242\0\u015f\0\u017a\0\242\0\u0144\0\u0195"+ + "\0\242\0\242\0\242\0\u01b0\0\u01cb\0\u01e6\0\u0201\0\u021c"+ + "\0\363\0\242\0\u0237\0\242\0\u0252"; + + private static int [] zzUnpackRowMap() { + int [] result = new int[37]; + int offset = 0; + offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackRowMap(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length() - 1; + while (i < l) { + int high = packed.charAt(i++) << 16; + result[j++] = high | packed.charAt(i++); + } + return j; + } + + /** + * The transition table of the DFA + */ + private static final int [] ZZ_TRANS = zzUnpacktrans(); + + private static final String ZZ_TRANS_PACKED_0 = + "\1\7\1\10\1\11\1\10\1\7\1\12\5\7\3\13"+ + "\1\14\6\7\1\15\2\7\1\11\3\7\1\16\1\11"+ + "\1\16\1\17\1\7\1\20\1\21\1\7\1\22\1\23"+ + "\1\24\1\7\1\22\1\25\1\22\1\26\1\27\1\30"+ + "\1\31\1\32\1\15\1\33\1\7\1\11\1\17\1\7"+ + "\1\34\1\16\1\11\1\16\21\34\1\15\5\34\1\35"+ + "\1\10\1\11\1\10\21\35\1\15\5\35\1\36\1\10"+ + "\1\11\1\10\21\36\1\15\5\36\1\7\1\16\1\11"+ + "\1\16\1\37\3\7\2\37\1\7\2\37\1\7\1\37"+ + "\1\7\1\26\4\7\1\15\1\7\1\37\1\11\2\7"+ + "\34\0\1\10\1\0\1\10\1\0\1\40\25\0\2\12"+ + "\2\0\26\12\14\0\2\41\1\0\1\14\10\0\1\41"+ + "\5\0\1\42\25\0\1\42\3\0\1\16\1\0\1\16"+ + "\1\0\1\43\47\0\1\44\23\0\1\26\30\0\1\22"+ + "\1\0\2\45\1\22\1\25\1\22\3\0\1\22\3\0"+ + "\1\45\25\0\1\27\10\0\1\34\3\0\21\34\1\0"+ + "\5\34\1\35\3\0\21\35\1\0\5\35\1\36\3\0"+ + "\21\36\1\0\5\36\4\0\1\37\3\0\2\37\1\0"+ + "\2\37\1\0\1\37\10\0\1\37\3\0\2\40\2\0"+ + "\26\40\1\0\2\43\2\0\26\43\14\0\2\45\1\0"+ + "\1\25\10\0\1\45\3\0"; + + private static int [] zzUnpacktrans() { + int [] result = new int[621]; + int offset = 0; + offset = zzUnpacktrans(ZZ_TRANS_PACKED_0, offset, result); + return result; + } + + private static int zzUnpacktrans(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + value--; + do result[j++] = value; while (--count > 0); + } + return j; + } + + + /* error codes */ + private static final int ZZ_UNKNOWN_ERROR = 0; + private static final int ZZ_NO_MATCH = 1; + private static final int ZZ_PUSHBACK_2BIG = 2; + + /* error messages for the codes above */ + private static final String[] ZZ_ERROR_MSG = { + "Unknown internal scanner error", + "Error: could not match input", + "Error: pushback value was too large" + }; + + /** + * ZZ_ATTRIBUTE[aState] contains the attributes of state {@code aState} + */ + private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); + + private static final String ZZ_ATTRIBUTE_PACKED_0 = + "\6\0\1\11\1\1\1\11\1\1\1\11\4\1\4\11"+ + "\2\1\1\11\2\1\3\11\5\1\1\0\1\11\1\1"+ + "\1\11\1\0"; + + private static int [] zzUnpackAttribute() { + int [] result = new int[37]; + int offset = 0; + offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackAttribute(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do result[j++] = value; while (--count > 0); + } + return j; + } + + /** the input device */ + private java.io.Reader zzReader; + + /** the current state of the DFA */ + private int zzState; + + /** the current lexical state */ + private int zzLexicalState = YYINITIAL; + + /** this buffer contains the current text to be matched and is + the source of the yytext() string */ + private CharSequence zzBuffer = ""; + + /** the textposition at the last accepting state */ + private int zzMarkedPos; + + /** the current text position in the buffer */ + private int zzCurrentPos; + + /** startRead marks the beginning of the yytext() string in the buffer */ + private int zzStartRead; + + /** endRead marks the last character in the buffer, that has been read + from input */ + private int zzEndRead; + + /** zzAtEOF == true <=> the scanner is at the EOF */ + private boolean zzAtEOF; + + /** Number of newlines encountered up to the start of the matched text. */ + @SuppressWarnings("unused") + private int yyline; + + /** Number of characters from the last newline up to the start of the matched text. */ + @SuppressWarnings("unused") + protected int yycolumn; + + /** Number of characters up to the start of the matched text. */ + @SuppressWarnings("unused") + private long yychar; + + /** Whether the scanner is currently at the beginning of a line. */ + @SuppressWarnings("unused") + private boolean zzAtBOL = true; + + /** Whether the user-EOF-code has already been executed. */ + private boolean zzEOFDone; + + /* user code: */ + public RequirementsLexer() { + this((java.io.Reader)null); + } + + + /** + * Creates a new scanner + * + * @param in the java.io.Reader to read input from. + */ + public RequirementsLexer(java.io.Reader in) { + this.zzReader = in; + } + + + /** Returns the maximum size of the scanner buffer, which limits the size of tokens. */ + private int zzMaxBufferLen() { + return Integer.MAX_VALUE; + } + + /** Whether the scanner buffer can grow to accommodate a larger token. */ + private boolean zzCanGrow() { + return true; + } + + /** + * Translates raw input code points to DFA table row + */ + private static int zzCMap(int input) { + int offset = input & 255; + return offset == input ? ZZ_CMAP_BLOCKS[offset] : ZZ_CMAP_BLOCKS[ZZ_CMAP_TOP[input >> 8] | offset]; + } + + public final int getTokenStart() { + return zzStartRead; + } + + public final int getTokenEnd() { + return getTokenStart() + yylength(); + } + + public void reset(CharSequence buffer, int start, int end, int initialState) { + zzBuffer = buffer; + zzCurrentPos = zzMarkedPos = zzStartRead = start; + zzAtEOF = false; + zzAtBOL = true; + zzEndRead = end; + yybegin(initialState); + } + + /** + * Refills the input buffer. + * + * @return {@code false}, iff there was new input. + * + * @exception java.io.IOException if any I/O-Error occurs + */ + private boolean zzRefill() throws java.io.IOException { + return true; + } + + + /** + * Returns the current lexical state. + */ + public final int yystate() { + return zzLexicalState; + } + + + /** + * Enters a new lexical state + * + * @param newState the new lexical state + */ + public final void yybegin(int newState) { + zzLexicalState = newState; + } + + + /** + * Returns the text matched by the current regular expression. + */ + public final CharSequence yytext() { + return zzBuffer.subSequence(zzStartRead, zzMarkedPos); + } + + + /** + * Returns the character at position {@code pos} from the + * matched text. + * + * It is equivalent to yytext().charAt(pos), but faster + * + * @param pos the position of the character to fetch. + * A value from 0 to yylength()-1. + * + * @return the character at position pos + */ + public final char yycharat(int pos) { + return zzBuffer.charAt(zzStartRead+pos); + } + + + /** + * Returns the length of the matched text region. + */ + public final int yylength() { + return zzMarkedPos-zzStartRead; + } + + + /** + * Reports an error that occurred while scanning. + * + * In a wellformed scanner (no or only correct usage of + * yypushback(int) and a match-all fallback rule) this method + * will only be called with things that "Can't Possibly Happen". + * If this method is called, something is seriously wrong + * (e.g. a JFlex bug producing a faulty scanner etc.). + * + * Usual syntax/scanner level error handling should be done + * in error fallback rules. + * + * @param errorCode the code of the errormessage to display + */ + private void zzScanError(int errorCode) { + String message; + try { + message = ZZ_ERROR_MSG[errorCode]; + } + catch (ArrayIndexOutOfBoundsException e) { + message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; + } + + throw new Error(message); + } + + + /** + * Pushes the specified amount of characters back into the input stream. + * + * They will be read again by then next call of the scanning method + * + * @param number the number of characters to be read again. + * This number must not be greater than yylength()! + */ + public void yypushback(int number) { + if ( number > yylength() ) + zzScanError(ZZ_PUSHBACK_2BIG); + + zzMarkedPos -= number; + } + + + /** + * Contains user EOF-code, which will be executed exactly once, + * when the end of file is reached + */ + private void zzDoEOF() { + if (!zzEOFDone) { + zzEOFDone = true; + + return; + } + } + + + /** + * Resumes scanning until the next regular expression is matched, + * the end of input is encountered or an I/O-Error occurs. + * + * @return the next token + * @exception java.io.IOException if any I/O-Error occurs + */ + public IElementType advance() throws java.io.IOException + { + int zzInput; + int zzAction; + + // cached fields: + int zzCurrentPosL; + int zzMarkedPosL; + int zzEndReadL = zzEndRead; + CharSequence zzBufferL = zzBuffer; + + int [] zzTransL = ZZ_TRANS; + int [] zzRowMapL = ZZ_ROWMAP; + int [] zzAttrL = ZZ_ATTRIBUTE; + + while (true) { + zzMarkedPosL = zzMarkedPos; + + zzAction = -1; + + zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; + + zzState = ZZ_LEXSTATE[zzLexicalState]; + + // set up zzAction for empty match case: + int zzAttributes = zzAttrL[zzState]; + if ( (zzAttributes & 1) == 1 ) { + zzAction = zzState; + } + + + zzForAction: { + while (true) { + + if (zzCurrentPosL < zzEndReadL) { + zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL); + zzCurrentPosL += Character.charCount(zzInput); + } + else if (zzAtEOF) { + zzInput = YYEOF; + break zzForAction; + } + else { + // store back cached positions + zzCurrentPos = zzCurrentPosL; + zzMarkedPos = zzMarkedPosL; + boolean eof = zzRefill(); + // get translated positions and possibly new buffer + zzCurrentPosL = zzCurrentPos; + zzMarkedPosL = zzMarkedPos; + zzBufferL = zzBuffer; + zzEndReadL = zzEndRead; + if (eof) { + zzInput = YYEOF; + break zzForAction; + } + else { + zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL); + zzCurrentPosL += Character.charCount(zzInput); + } + } + int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMap(zzInput) ]; + if (zzNext == -1) break zzForAction; + zzState = zzNext; + + zzAttributes = zzAttrL[zzState]; + if ( (zzAttributes & 1) == 1 ) { + zzAction = zzState; + zzMarkedPosL = zzCurrentPosL; + if ( (zzAttributes & 8) == 8 ) break zzForAction; + } + + } + } + + // store back cached position + zzMarkedPos = zzMarkedPosL; + + if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { + zzAtEOF = true; + zzDoEOF(); + return null; + } + else { + switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { + case 1: + { yybegin(YYINITIAL); return BAD_CHARACTER; + } + // fall through + case 25: break; + case 2: + { return WHITE_SPACE; + } + // fall through + case 26: break; + case 3: + { yybegin(YYINITIAL); return CRLF; + } + // fall through + case 27: break; + case 4: + { return COMMENT; + } + // fall through + case 28: break; + case 5: + { yybegin(OTHER_SPEC); yypushback(yylength()); + } + // fall through + case 29: break; + case 6: + { yybegin(REQ); yypushback(yylength()); + } + // fall through + case 30: break; + case 7: + { return BACKSLASH; + } + // fall through + case 31: break; + case 8: + { return LPARENTHESIS; + } + // fall through + case 32: break; + case 9: + { return RPARENTHESIS; + } + // fall through + case 33: break; + case 10: + { yybegin(URI_SPEC); yypushback(yylength()); + } + // fall through + case 34: break; + case 11: + { return COMMA; + } + // fall through + case 35: break; + case 12: + { return IDENTIFIER; + } + // fall through + case 36: break; + case 13: + { yybegin(REQ_OTHER); yypushback(yylength()); + } + // fall through + case 37: break; + case 14: + { yybegin(HANDLE_VERSION); return VERSION_CMP; + } + // fall through + case 38: break; + case 15: + { yybegin(REQ_OTHER); return AT; + } + // fall through + case 39: break; + case 16: + { return LSBRACE; + } + // fall through + case 40: break; + case 17: + { return RSBRACE; + } + // fall through + case 41: break; + case 18: + { return REQ_PART; + } + // fall through + case 42: break; + case 19: + { return URI_PART; + } + // fall through + case 43: break; + case 20: + { return OTHER_PART; + } + // fall through + case 44: break; + case 21: + { yybegin(REQ); return VERSION; + } + // fall through + case 45: break; + case 22: + { yybegin(YYINITIAL); return COMMENT; + } + // fall through + case 46: break; + case 23: + { + } + // fall through + case 47: break; + case 24: + { yybegin(YYINITIAL); return REQ_COMMENT; + } + // fall through + case 48: break; + default: + zzScanError(ZZ_NO_MATCH); + } + } + } + } + + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/parser/RequirementsParser.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/parser/RequirementsParser.java new file mode 100644 index 0000000..cb5a8f6 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/parser/RequirementsParser.java @@ -0,0 +1,427 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.parser; + +import com.intellij.lang.ASTNode; +import com.intellij.lang.LightPsiParser; +import com.intellij.lang.PsiBuilder; +import com.intellij.lang.PsiBuilder.Marker; +import com.intellij.lang.PsiParser; +import com.intellij.psi.tree.IElementType; + +import static com.intellij.lang.parser.GeneratedParserUtilBase.*; +import static org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.RequirementsTypes.*; + +@SuppressWarnings({"SimplifiableIfStatement", "UnusedAssignment"}) +public class RequirementsParser implements PsiParser, LightPsiParser { + + public ASTNode parse(IElementType t, PsiBuilder b) { + parseLight(t, b); + return b.getTreeBuilt(); + } + + public void parseLight(IElementType t, PsiBuilder b) { + boolean r; + b = adapt_builder_(t, b, this, null); + Marker m = enter_section_(b, 0, _COLLAPSE_, null); + r = parse_root_(t, b); + exit_section_(b, 0, m, t, r, true, TRUE_CONDITION); + } + + protected boolean parse_root_(IElementType t, PsiBuilder b) { + return parse_root_(t, b, 0); + } + + static boolean parse_root_(IElementType t, PsiBuilder b, int l) { + return file(b, l + 1); + } + + /* ********************************************************** */ + // LSBRACE extras_list? RSBRACE + static boolean extras(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "extras")) return false; + if (!nextTokenIs(b, LSBRACE)) return false; + boolean r, p; + Marker m = enter_section_(b, l, _NONE_); + r = consumeToken(b, LSBRACE); + p = r; // pin = 1 + r = r && report_error_(b, extras_1(b, l + 1)); + r = p && consumeToken(b, RSBRACE) && r; + exit_section_(b, l, m, r, p, null); + return r || p; + } + + // extras_list? + private static boolean extras_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "extras_1")) return false; + extras_list(b, l + 1); + return true; + } + + /* ********************************************************** */ + // IDENTIFIER (COMMA IDENTIFIER)* + public static boolean extras_list(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "extras_list")) return false; + if (!nextTokenIs(b, IDENTIFIER)) return false; + boolean r, p; + Marker m = enter_section_(b, l, _NONE_, EXTRAS_LIST, null); + r = consumeToken(b, IDENTIFIER); + p = r; // pin = 1 + r = r && extras_list_1(b, l + 1); + exit_section_(b, l, m, r, p, null); + return r || p; + } + + // (COMMA IDENTIFIER)* + private static boolean extras_list_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "extras_list_1")) return false; + while (true) { + int c = current_position_(b); + if (!extras_list_1_0(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "extras_list_1", c)) break; + } + return true; + } + + // COMMA IDENTIFIER + private static boolean extras_list_1_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "extras_list_1_0")) return false; + boolean r, p; + Marker m = enter_section_(b, l, _NONE_); + r = consumeTokens(b, 1, COMMA, IDENTIFIER); + p = r; // pin = 1 + exit_section_(b, l, m, r, p, null); + return r || p; + } + + /* ********************************************************** */ + // line* + static boolean file(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "file")) return false; + while (true) { + int c = current_position_(b); + if (!line(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "file", c)) break; + } + return true; + } + + /* ********************************************************** */ + // spec | COMMENT | CRLF + static boolean line(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "line")) return false; + boolean r; + r = spec(b, l + 1); + if (!r) r = consumeToken(b, COMMENT); + if (!r) r = consumeToken(b, CRLF); + return r; + } + + /* ********************************************************** */ + // pkg_name extras? (versionspec | AT)? (REQ_PART | BACKSLASH)* name_req_comment? + public static boolean name_req(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "name_req")) return false; + if (!nextTokenIs(b, IDENTIFIER)) return false; + boolean r; + Marker m = enter_section_(b); + r = pkg_name(b, l + 1); + r = r && name_req_1(b, l + 1); + r = r && name_req_2(b, l + 1); + r = r && name_req_3(b, l + 1); + r = r && name_req_4(b, l + 1); + exit_section_(b, m, NAME_REQ, r); + return r; + } + + // extras? + private static boolean name_req_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "name_req_1")) return false; + extras(b, l + 1); + return true; + } + + // (versionspec | AT)? + private static boolean name_req_2(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "name_req_2")) return false; + name_req_2_0(b, l + 1); + return true; + } + + // versionspec | AT + private static boolean name_req_2_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "name_req_2_0")) return false; + boolean r; + r = versionspec(b, l + 1); + if (!r) r = consumeToken(b, AT); + return r; + } + + // (REQ_PART | BACKSLASH)* + private static boolean name_req_3(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "name_req_3")) return false; + while (true) { + int c = current_position_(b); + if (!name_req_3_0(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "name_req_3", c)) break; + } + return true; + } + + // REQ_PART | BACKSLASH + private static boolean name_req_3_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "name_req_3_0")) return false; + boolean r; + r = consumeToken(b, REQ_PART); + if (!r) r = consumeToken(b, BACKSLASH); + return r; + } + + // name_req_comment? + private static boolean name_req_4(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "name_req_4")) return false; + name_req_comment(b, l + 1); + return true; + } + + /* ********************************************************** */ + // REQ_COMMENT + public static boolean name_req_comment(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "name_req_comment")) return false; + if (!nextTokenIs(b, REQ_COMMENT)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, REQ_COMMENT); + exit_section_(b, m, NAME_REQ_COMMENT, r); + return r; + } + + /* ********************************************************** */ + // OTHER_PART (OTHER_PART | BACKSLASH)* COMMENT? + public static boolean other_spec(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "other_spec")) return false; + if (!nextTokenIs(b, OTHER_PART)) return false; + boolean r, p; + Marker m = enter_section_(b, l, _NONE_, OTHER_SPEC, null); + r = consumeToken(b, OTHER_PART); + p = r; // pin = 1 + r = r && report_error_(b, other_spec_1(b, l + 1)); + r = p && other_spec_2(b, l + 1) && r; + exit_section_(b, l, m, r, p, null); + return r || p; + } + + // (OTHER_PART | BACKSLASH)* + private static boolean other_spec_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "other_spec_1")) return false; + while (true) { + int c = current_position_(b); + if (!other_spec_1_0(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "other_spec_1", c)) break; + } + return true; + } + + // OTHER_PART | BACKSLASH + private static boolean other_spec_1_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "other_spec_1_0")) return false; + boolean r; + r = consumeToken(b, OTHER_PART); + if (!r) r = consumeToken(b, BACKSLASH); + return r; + } + + // COMMENT? + private static boolean other_spec_2(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "other_spec_2")) return false; + consumeToken(b, COMMENT); + return true; + } + + /* ********************************************************** */ + // IDENTIFIER + public static boolean pkg_name(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "pkg_name")) return false; + if (!nextTokenIs(b, IDENTIFIER)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, IDENTIFIER); + exit_section_(b, m, PKG_NAME, r); + return r; + } + + /* ********************************************************** */ + // name_req | uri_req | other_spec + static boolean spec(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "spec")) return false; + boolean r; + r = name_req(b, l + 1); + if (!r) r = uri_req(b, l + 1); + if (!r) r = other_spec(b, l + 1); + return r; + } + + /* ********************************************************** */ + // (pkg_name extras?)? URI_PART (URI_PART | BACKSLASH)* COMMENT? + public static boolean uri_req(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "uri_req")) return false; + if (!nextTokenIs(b, "", IDENTIFIER, URI_PART)) return false; + boolean r, p; + Marker m = enter_section_(b, l, _NONE_, URI_REQ, ""); + r = uri_req_0(b, l + 1); + r = r && consumeToken(b, URI_PART); + p = r; // pin = 2 + r = r && report_error_(b, uri_req_2(b, l + 1)); + r = p && uri_req_3(b, l + 1) && r; + exit_section_(b, l, m, r, p, null); + return r || p; + } + + // (pkg_name extras?)? + private static boolean uri_req_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "uri_req_0")) return false; + uri_req_0_0(b, l + 1); + return true; + } + + // pkg_name extras? + private static boolean uri_req_0_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "uri_req_0_0")) return false; + boolean r; + Marker m = enter_section_(b); + r = pkg_name(b, l + 1); + r = r && uri_req_0_0_1(b, l + 1); + exit_section_(b, m, null, r); + return r; + } + + // extras? + private static boolean uri_req_0_0_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "uri_req_0_0_1")) return false; + extras(b, l + 1); + return true; + } + + // (URI_PART | BACKSLASH)* + private static boolean uri_req_2(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "uri_req_2")) return false; + while (true) { + int c = current_position_(b); + if (!uri_req_2_0(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "uri_req_2", c)) break; + } + return true; + } + + // URI_PART | BACKSLASH + private static boolean uri_req_2_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "uri_req_2_0")) return false; + boolean r; + r = consumeToken(b, URI_PART); + if (!r) r = consumeToken(b, BACKSLASH); + return r; + } + + // COMMENT? + private static boolean uri_req_3(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "uri_req_3")) return false; + consumeToken(b, COMMENT); + return true; + } + + /* ********************************************************** */ + // VERSION_CMP + public static boolean version_cmp_value(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "version_cmp_value")) return false; + if (!nextTokenIs(b, VERSION_CMP)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, VERSION_CMP); + exit_section_(b, m, VERSION_CMP_VALUE, r); + return r; + } + + /* ********************************************************** */ + // version_one (COMMA version_one)* + static boolean version_many(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "version_many")) return false; + if (!nextTokenIs(b, VERSION_CMP)) return false; + boolean r; + Marker m = enter_section_(b); + r = version_one(b, l + 1); + r = r && version_many_1(b, l + 1); + exit_section_(b, m, null, r); + return r; + } + + // (COMMA version_one)* + private static boolean version_many_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "version_many_1")) return false; + while (true) { + int c = current_position_(b); + if (!version_many_1_0(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "version_many_1", c)) break; + } + return true; + } + + // COMMA version_one + private static boolean version_many_1_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "version_many_1_0")) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, COMMA); + r = r && version_one(b, l + 1); + exit_section_(b, m, null, r); + return r; + } + + /* ********************************************************** */ + // version_cmp_value version_value + public static boolean version_one(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "version_one")) return false; + if (!nextTokenIs(b, VERSION_CMP)) return false; + boolean r; + Marker m = enter_section_(b); + r = version_cmp_value(b, l + 1); + r = r && version_value(b, l + 1); + exit_section_(b, m, VERSION_ONE, r); + return r; + } + + /* ********************************************************** */ + // VERSION + public static boolean version_value(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "version_value")) return false; + if (!nextTokenIs(b, VERSION)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, VERSION); + exit_section_(b, m, VERSION_VALUE, r); + return r; + } + + /* ********************************************************** */ + // LPARENTHESIS version_many RPARENTHESIS | version_many + public static boolean versionspec(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "versionspec")) return false; + if (!nextTokenIs(b, "", LPARENTHESIS, VERSION_CMP)) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, VERSIONSPEC, ""); + r = versionspec_0(b, l + 1); + if (!r) r = version_many(b, l + 1); + exit_section_(b, l, m, r, false, null); + return r; + } + + // LPARENTHESIS version_many RPARENTHESIS + private static boolean versionspec_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "versionspec_0")) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, LPARENTHESIS); + r = r && version_many(b, l + 1); + r = r && consumeToken(b, RPARENTHESIS); + exit_section_(b, m, null, r); + return r; + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/ExtrasList.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/ExtrasList.java new file mode 100644 index 0000000..b23ab69 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/ExtrasList.java @@ -0,0 +1,8 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; + +public interface ExtrasList extends PsiElement { + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/NameReq.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/NameReq.java new file mode 100644 index 0000000..f988f0d --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/NameReq.java @@ -0,0 +1,22 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface NameReq extends PsiElement { + + @Nullable + ExtrasList getExtrasList(); + + @Nullable + NameReqComment getNameReqComment(); + + @NotNull + PkgName getPkgName(); + + @Nullable + Versionspec getVersionspec(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/NameReqComment.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/NameReqComment.java new file mode 100644 index 0000000..300ae39 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/NameReqComment.java @@ -0,0 +1,8 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; + +public interface NameReqComment extends PsiElement { + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/OtherSpec.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/OtherSpec.java new file mode 100644 index 0000000..1660eff --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/OtherSpec.java @@ -0,0 +1,8 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; + +public interface OtherSpec extends PsiElement { + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/PkgName.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/PkgName.java new file mode 100644 index 0000000..8eac400 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/PkgName.java @@ -0,0 +1,8 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; + +public interface PkgName extends PsiElement { + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsTypes.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsTypes.java new file mode 100644 index 0000000..90c1bd8 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsTypes.java @@ -0,0 +1,75 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.tree.IElementType; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl.*; + +public interface RequirementsTypes { + + IElementType EXTRAS_LIST = new RequirementsElementType("EXTRAS_LIST"); + IElementType NAME_REQ = new RequirementsElementType("NAME_REQ"); + IElementType NAME_REQ_COMMENT = new RequirementsElementType("NAME_REQ_COMMENT"); + IElementType OTHER_SPEC = new RequirementsElementType("OTHER_SPEC"); + IElementType PKG_NAME = new RequirementsElementType("PKG_NAME"); + IElementType URI_REQ = new RequirementsElementType("URI_REQ"); + IElementType VERSIONSPEC = new RequirementsElementType("VERSIONSPEC"); + IElementType VERSION_CMP_VALUE = new RequirementsElementType("VERSION_CMP_VALUE"); + IElementType VERSION_ONE = new RequirementsElementType("VERSION_ONE"); + IElementType VERSION_VALUE = new RequirementsElementType("VERSION_VALUE"); + + IElementType AT = new RequirementsTokenType("AT"); + IElementType BACKSLASH = new RequirementsTokenType("BACKSLASH"); + IElementType COMMA = new RequirementsTokenType("COMMA"); + IElementType COMMENT = new RequirementsTokenType("COMMENT"); + IElementType CRLF = new RequirementsTokenType("CRLF"); + IElementType IDENTIFIER = new RequirementsTokenType("IDENTIFIER"); + IElementType LPARENTHESIS = new RequirementsTokenType("LPARENTHESIS"); + IElementType LSBRACE = new RequirementsTokenType("LSBRACE"); + IElementType OTHER_PART = new RequirementsTokenType("OTHER_PART"); + IElementType REQ_COMMENT = new RequirementsTokenType("REQ_COMMENT"); + IElementType REQ_PART = new RequirementsTokenType("REQ_PART"); + IElementType RPARENTHESIS = new RequirementsTokenType("RPARENTHESIS"); + IElementType RSBRACE = new RequirementsTokenType("RSBRACE"); + IElementType URI_PART = new RequirementsTokenType("URI_PART"); + IElementType VERSION = new RequirementsTokenType("VERSION"); + IElementType VERSION_CMP = new RequirementsTokenType("VERSION_CMP"); + + class Factory { + public static PsiElement createElement(ASTNode node) { + IElementType type = node.getElementType(); + if (type == EXTRAS_LIST) { + return new ExtrasListImpl(node); + } + else if (type == NAME_REQ) { + return new NameReqImpl(node); + } + else if (type == NAME_REQ_COMMENT) { + return new NameReqCommentImpl(node); + } + else if (type == OTHER_SPEC) { + return new OtherSpecImpl(node); + } + else if (type == PKG_NAME) { + return new PkgNameImpl(node); + } + else if (type == URI_REQ) { + return new UriReqImpl(node); + } + else if (type == VERSIONSPEC) { + return new VersionspecImpl(node); + } + else if (type == VERSION_CMP_VALUE) { + return new VersionCmpValueImpl(node); + } + else if (type == VERSION_ONE) { + return new VersionOneImpl(node); + } + else if (type == VERSION_VALUE) { + return new VersionValueImpl(node); + } + throw new AssertionError("Unknown element type: " + type); + } + } +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/UriReq.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/UriReq.java new file mode 100644 index 0000000..025ea8c --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/UriReq.java @@ -0,0 +1,15 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.Nullable; + +public interface UriReq extends PsiElement { + + @Nullable + ExtrasList getExtrasList(); + + @Nullable + PkgName getPkgName(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/VersionCmpValue.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/VersionCmpValue.java new file mode 100644 index 0000000..5607f4e --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/VersionCmpValue.java @@ -0,0 +1,8 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; + +public interface VersionCmpValue extends PsiElement { + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/VersionOne.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/VersionOne.java new file mode 100644 index 0000000..59ff257 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/VersionOne.java @@ -0,0 +1,15 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; + +public interface VersionOne extends PsiElement { + + @NotNull + VersionCmpValue getVersionCmpValue(); + + @NotNull + VersionValue getVersionValue(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/VersionValue.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/VersionValue.java new file mode 100644 index 0000000..aaf0acd --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/VersionValue.java @@ -0,0 +1,8 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; + +public interface VersionValue extends PsiElement { + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/Versionspec.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/Versionspec.java new file mode 100644 index 0000000..da36083 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/Versionspec.java @@ -0,0 +1,14 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface Versionspec extends PsiElement { + + @NotNull + List getVersionOneList(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/Visitor.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/Visitor.java new file mode 100644 index 0000000..65b83fe --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/Visitor.java @@ -0,0 +1,54 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import org.jetbrains.annotations.NotNull; + +public class Visitor extends PsiElementVisitor { + + public void visitExtrasList(@NotNull ExtrasList o) { + visitPsiElement(o); + } + + public void visitNameReq(@NotNull NameReq o) { + visitPsiElement(o); + } + + public void visitNameReqComment(@NotNull NameReqComment o) { + visitPsiElement(o); + } + + public void visitOtherSpec(@NotNull OtherSpec o) { + visitPsiElement(o); + } + + public void visitPkgName(@NotNull PkgName o) { + visitPsiElement(o); + } + + public void visitUriReq(@NotNull UriReq o) { + visitPsiElement(o); + } + + public void visitVersionCmpValue(@NotNull VersionCmpValue o) { + visitPsiElement(o); + } + + public void visitVersionOne(@NotNull VersionOne o) { + visitPsiElement(o); + } + + public void visitVersionValue(@NotNull VersionValue o) { + visitPsiElement(o); + } + + public void visitVersionspec(@NotNull Versionspec o) { + visitPsiElement(o); + } + + public void visitPsiElement(@NotNull PsiElement o) { + visitElement(o); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/ExtrasListImpl.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/ExtrasListImpl.java new file mode 100644 index 0000000..87db6bf --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/ExtrasListImpl.java @@ -0,0 +1,27 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElementVisitor; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.ExtrasList; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.Visitor; +import org.jetbrains.annotations.NotNull; + +public class ExtrasListImpl extends ASTWrapperPsiElement implements ExtrasList { + + public ExtrasListImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull Visitor visitor) { + visitor.visitExtrasList(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof Visitor) accept((Visitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/NameReqCommentImpl.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/NameReqCommentImpl.java new file mode 100644 index 0000000..4b41f86 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/NameReqCommentImpl.java @@ -0,0 +1,27 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElementVisitor; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.NameReqComment; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.Visitor; +import org.jetbrains.annotations.NotNull; + +public class NameReqCommentImpl extends ASTWrapperPsiElement implements NameReqComment { + + public NameReqCommentImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull Visitor visitor) { + visitor.visitNameReqComment(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof Visitor) accept((Visitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/NameReqImpl.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/NameReqImpl.java new file mode 100644 index 0000000..144a470 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/NameReqImpl.java @@ -0,0 +1,51 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElementVisitor; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class NameReqImpl extends ASTWrapperPsiElement implements NameReq { + + public NameReqImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull Visitor visitor) { + visitor.visitNameReq(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof Visitor) accept((Visitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public ExtrasList getExtrasList() { + return findChildByClass(ExtrasList.class); + } + + @Override + @Nullable + public NameReqComment getNameReqComment() { + return findChildByClass(NameReqComment.class); + } + + @Override + @NotNull + public PkgName getPkgName() { + return findNotNullChildByClass(PkgName.class); + } + + @Override + @Nullable + public Versionspec getVersionspec() { + return findChildByClass(Versionspec.class); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/OtherSpecImpl.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/OtherSpecImpl.java new file mode 100644 index 0000000..28bcb42 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/OtherSpecImpl.java @@ -0,0 +1,27 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElementVisitor; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.OtherSpec; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.Visitor; +import org.jetbrains.annotations.NotNull; + +public class OtherSpecImpl extends ASTWrapperPsiElement implements OtherSpec { + + public OtherSpecImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull Visitor visitor) { + visitor.visitOtherSpec(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof Visitor) accept((Visitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/PkgNameImpl.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/PkgNameImpl.java new file mode 100644 index 0000000..40dbda0 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/PkgNameImpl.java @@ -0,0 +1,27 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElementVisitor; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.PkgName; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.Visitor; +import org.jetbrains.annotations.NotNull; + +public class PkgNameImpl extends ASTWrapperPsiElement implements PkgName { + + public PkgNameImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull Visitor visitor) { + visitor.visitPkgName(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof Visitor) accept((Visitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/UriReqImpl.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/UriReqImpl.java new file mode 100644 index 0000000..0f1a3cf --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/UriReqImpl.java @@ -0,0 +1,42 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElementVisitor; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.ExtrasList; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.PkgName; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.UriReq; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.Visitor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class UriReqImpl extends ASTWrapperPsiElement implements UriReq { + + public UriReqImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull Visitor visitor) { + visitor.visitUriReq(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof Visitor) accept((Visitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public ExtrasList getExtrasList() { + return findChildByClass(ExtrasList.class); + } + + @Override + @Nullable + public PkgName getPkgName() { + return findChildByClass(PkgName.class); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionCmpValueImpl.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionCmpValueImpl.java new file mode 100644 index 0000000..eb4e522 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionCmpValueImpl.java @@ -0,0 +1,27 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElementVisitor; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.VersionCmpValue; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.Visitor; +import org.jetbrains.annotations.NotNull; + +public class VersionCmpValueImpl extends ASTWrapperPsiElement implements VersionCmpValue { + + public VersionCmpValueImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull Visitor visitor) { + visitor.visitVersionCmpValue(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof Visitor) accept((Visitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionOneImpl.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionOneImpl.java new file mode 100644 index 0000000..0d82b1f --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionOneImpl.java @@ -0,0 +1,41 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElementVisitor; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.VersionCmpValue; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.VersionOne; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.VersionValue; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.Visitor; +import org.jetbrains.annotations.NotNull; + +public class VersionOneImpl extends ASTWrapperPsiElement implements VersionOne { + + public VersionOneImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull Visitor visitor) { + visitor.visitVersionOne(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof Visitor) accept((Visitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public VersionCmpValue getVersionCmpValue() { + return findNotNullChildByClass(VersionCmpValue.class); + } + + @Override + @NotNull + public VersionValue getVersionValue() { + return findNotNullChildByClass(VersionValue.class); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionValueImpl.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionValueImpl.java new file mode 100644 index 0000000..c1a289f --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionValueImpl.java @@ -0,0 +1,27 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElementVisitor; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.VersionValue; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.Visitor; +import org.jetbrains.annotations.NotNull; + +public class VersionValueImpl extends ASTWrapperPsiElement implements VersionValue { + + public VersionValueImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull Visitor visitor) { + visitor.visitVersionValue(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof Visitor) accept((Visitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionspecImpl.java b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionspecImpl.java new file mode 100644 index 0000000..0c4d31c --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/impl/VersionspecImpl.java @@ -0,0 +1,37 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.VersionOne; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.Versionspec; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.Visitor; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class VersionspecImpl extends ASTWrapperPsiElement implements Versionspec { + + public VersionspecImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull Visitor visitor) { + visitor.visitVersionspec(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof Visitor) accept((Visitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public List getVersionOneList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, VersionOne.class); + } + +} diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/CAAnnotator.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/CAAnnotator.java index 6ca6b50..d8165fd 100644 --- a/src/main/java/org/jboss/tools/intellij/componentanalysis/CAAnnotator.java +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/CAAnnotator.java @@ -185,6 +185,8 @@ private String getPackageManager(String file) { return "npm"; case "go.mod": return "go"; + case "requirements.txt": + return "python"; default: return null; } diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/CAIntentionAction.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/CAIntentionAction.java index 1a0c468..caf1be5 100644 --- a/src/main/java/org/jboss/tools/intellij/componentanalysis/CAIntentionAction.java +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/CAIntentionAction.java @@ -44,7 +44,8 @@ public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file } return "pom.xml".equals(file.getName()) || "package.json".equals(file.getName()) - || "go.mod".equals(file.getName()); + || "go.mod".equals(file.getName()) + || "requirements.txt".equals(file.getName()); } @Override diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/PipCAAnnotator.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/PipCAAnnotator.java new file mode 100644 index 0000000..d364bb1 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/PipCAAnnotator.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.componentanalysis.pypi; + +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import org.jboss.tools.intellij.componentanalysis.CAAnnotator; +import org.jboss.tools.intellij.componentanalysis.Dependency; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.NameReq; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.NameReqComment; + +import java.util.*; + +public class PipCAAnnotator extends CAAnnotator { + @Override + protected String getInspectionShortName() { + return PipCAInspection.SHORT_NAME; + } + + @Override + protected Map> getDependencies(PsiFile file) { + if ("requirements.txt".equals(file.getName())) { + Map> resultMap = new HashMap<>(); + Arrays.stream(file.getChildren()) + .filter(e -> e instanceof NameReq) + .map(e -> (NameReq) e) + .filter(r -> Arrays.stream(r.getChildren()) + .filter(c -> c instanceof NameReqComment) + .map(c -> (NameReqComment) c) + .noneMatch(c -> { + String comment = c.getText().trim(); + if (!comment.isEmpty() && '#' == comment.charAt(0)) { + return "exhortignore".equals(comment.substring(1).trim()); + } + return false; + })) + .forEach(r -> { + String name = r.getPkgName().getText(); + String version = r.getVersionspec() != null ? r.getVersionspec().getText() : null; + Dependency dp = new Dependency("pypi", null, name, version); + resultMap.computeIfAbsent(dp, k -> new LinkedList<>()).add(r); + }); + return resultMap; + } + return Collections.emptyMap(); + } +} diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/PipCAInspection.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/PipCAInspection.java new file mode 100644 index 0000000..c3f2318 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/PipCAInspection.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.componentanalysis.pypi; + +import com.intellij.codeHighlighting.HighlightDisplayLevel; +import com.intellij.codeInspection.LocalInspectionTool; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +public class PipCAInspection extends LocalInspectionTool { + + @NonNls + + public static final String SHORT_NAME = "PipCAInspection"; + + @Override + public @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull String getGroupDisplayName() { + return "Python"; + } + + @Override + public @NonNls @NotNull String getShortName() { + return SHORT_NAME; + } + + @Override + public @NotNull HighlightDisplayLevel getDefaultLevel() { + return HighlightDisplayLevel.ERROR; + } +} diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/Requirements.bnf b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/Requirements.bnf new file mode 100644 index 0000000..7eab345 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/Requirements.bnf @@ -0,0 +1,39 @@ +{ + parserClass="org.jboss.tools.intellij.componentanalysis.pypi.requirements.parser.RequirementsParser" + parserUtilClass="com.intellij.lang.parser.GeneratedParserUtilBase" + + extends="com.intellij.extapi.psi.ASTWrapperPsiElement" + + psiClassPrefix="" + psiImplClassSuffix="Impl" + psiPackage="org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi" + psiImplPackage="org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.impl" + + elementTypeHolderClass="org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.RequirementsTypes" + elementTypeClass="org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.RequirementsElementType" + tokenTypeClass="org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.RequirementsTokenType" +} + +file ::= line* + +private line ::= (spec | COMMENT | CRLF) +private spec ::= (name_req | uri_req | other_spec) + +name_req ::= (pkg_name extras? (versionspec | AT)? (REQ_PART | BACKSLASH)* name_req_comment?) {pin=5} + +pkg_name ::= IDENTIFIER + +private extras ::= LSBRACE extras_list? RSBRACE {pin=1} +extras_list ::= IDENTIFIER (COMMA IDENTIFIER)* {pin(".*")=1} + +versionspec ::= LPARENTHESIS version_many RPARENTHESIS | version_many +private version_many ::= version_one (COMMA version_one)* +version_one ::= version_cmp_value version_value +version_cmp_value ::= VERSION_CMP +version_value ::= VERSION + +name_req_comment ::= REQ_COMMENT + +uri_req ::= (pkg_name extras?)? URI_PART (URI_PART | BACKSLASH)* COMMENT? {pin=2} + +other_spec ::= OTHER_PART (OTHER_PART | BACKSLASH)* COMMENT? {pin=1} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/Requirements.flex b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/Requirements.flex new file mode 100644 index 0000000..8081370 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/Requirements.flex @@ -0,0 +1,111 @@ +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.lexer; + +import com.intellij.lexer.FlexLexer; +import com.intellij.psi.tree.IElementType; + +import static com.intellij.psi.TokenType.BAD_CHARACTER; +import static com.intellij.psi.TokenType.WHITE_SPACE; +import static org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.RequirementsTypes.*; + +%% + +%{ + public RequirementsLexer() { + this((java.io.Reader)null); + } +%} + +%public +%class RequirementsLexer +%implements FlexLexer +%function advance +%type IElementType +%unicode +%eof{ + return; +%eof} + +CRLF=[\n|\r|\r\n] +WHITE_SPACE=[^\S\r\n]+ +BACKSLASH="\\" +COMMA="," +LSBRACE="[" +RSBRACE="]" +LPARENTHESIS = "(" +RPARENTHESIS = ")" +AT="@" + +COMMENT=#.* + +IDENTIFIER=[a-zA-Z0-9](([a-zA-Z0-9_.-])*[a-zA-Z0-9])* +VERSION_CMP=("<=" | "<" | "!=" | "===" | "==" | ">=" | ">" | "~=") +VERSION=([a-zA-Z0-9_.*+!-])+ +REQ_COMMENT={WHITE_SPACE}{COMMENT} +REQ_OPTION=(";" | "--") +URI_OPTION=("/" | "@" | "+" | ":") +IDENTIFIER_URI={IDENTIFIER}{URI_OPTION} +OTHER_OPTION=("-" | "." | "/") + +OTHER=[^\s\r\n\t\f\\]+ + +%state REQ +%state REQ_OTHER +%state URI_SPEC +%state OTHER_SPEC +%state HANDLE_VERSION + +%% + { + {COMMENT} { return COMMENT; } + {IDENTIFIER} { yybegin(REQ); yypushback(yylength()); } + {OTHER_OPTION} { yybegin(OTHER_SPEC); yypushback(yylength()); } +} + + { + {IDENTIFIER_URI} { yybegin(URI_SPEC); yypushback(yylength()); } + + {IDENTIFIER} { return IDENTIFIER; } + {VERSION_CMP} { yybegin(HANDLE_VERSION); return VERSION_CMP; } + + {COMMA} { return COMMA; } + {LPARENTHESIS} { return LPARENTHESIS; } + {RPARENTHESIS} { return RPARENTHESIS; } + {LSBRACE} { return LSBRACE; } + {RSBRACE} { return RSBRACE; } + {AT} { yybegin(REQ_OTHER); return AT; } + {REQ_COMMENT} { yybegin(YYINITIAL); return REQ_COMMENT; } + + {URI_OPTION} { yybegin(URI_SPEC); yypushback(yylength()); } + {REQ_OPTION} { yybegin(REQ_OTHER); yypushback(yylength()); } +} + + { + {VERSION} { yybegin(REQ); return VERSION; } + {REQ_COMMENT} { yybegin(YYINITIAL); return REQ_COMMENT; } + {REQ_OPTION} { yybegin(REQ_OTHER); yypushback(yylength()); } +} + + { + {REQ_COMMENT} { yybegin(YYINITIAL); return REQ_COMMENT; } + {OTHER} { return REQ_PART; } +} + + { + {OTHER} { return URI_PART; } +} + + { + {OTHER} { return OTHER_PART; } +} + +{WHITE_SPACE}{COMMENT} { yybegin(YYINITIAL); return COMMENT; } + +{WHITE_SPACE} { return WHITE_SPACE; } + +{BACKSLASH}{CRLF} { } + +{BACKSLASH} { return BACKSLASH; } + +{CRLF} { yybegin(YYINITIAL); return CRLF; } + +[^] { yybegin(YYINITIAL); return BAD_CHARACTER; } diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/filetype/RequirementsFileType.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/filetype/RequirementsFileType.java new file mode 100644 index 0000000..9983f7d --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/filetype/RequirementsFileType.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + + +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.filetype; + +import com.intellij.openapi.fileTypes.LanguageFileType; +import com.intellij.openapi.util.NlsContexts; +import com.intellij.openapi.util.NlsSafe; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.lang.RequirementsLanguage; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +public class RequirementsFileType extends LanguageFileType { + + public static final RequirementsFileType INSTANCE = new RequirementsFileType(); + + RequirementsFileType() { + super(RequirementsLanguage.INSTANCE); + } + + @Override + public @NonNls @NotNull String getName() { + return "rhda-requirements"; + } + + @Override + public @NlsContexts.Label @NotNull String getDescription() { + return "Items to be installed by pip"; + } + + @Override + public @NlsSafe @NotNull String getDefaultExtension() { + return "txt"; + } + + @Override + public @Nullable Icon getIcon() { + return null; + } +} diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/lang/RequirementsLanguage.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/lang/RequirementsLanguage.java new file mode 100644 index 0000000..7937293 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/lang/RequirementsLanguage.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.lang; + +import com.intellij.lang.Language; + +public class RequirementsLanguage extends Language { + + public final static RequirementsLanguage INSTANCE = new RequirementsLanguage(); + + private RequirementsLanguage() { + super("rhda-requirements"); + } +} diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/lexer/RequirementsLexerAdapter.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/lexer/RequirementsLexerAdapter.java new file mode 100644 index 0000000..8410b17 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/lexer/RequirementsLexerAdapter.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.lexer; + +import com.intellij.lexer.FlexAdapter; + +public class RequirementsLexerAdapter extends FlexAdapter { + public RequirementsLexerAdapter() { + super(new RequirementsLexer(null)); + } +} + diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsElementType.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsElementType.java new file mode 100644 index 0000000..455c08d --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsElementType.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.tree.IElementType; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.lang.RequirementsLanguage; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +public class RequirementsElementType extends IElementType { + public RequirementsElementType(@NonNls @NotNull String debugName) { + super(debugName, RequirementsLanguage.INSTANCE); + } +} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsFile.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsFile.java new file mode 100644 index 0000000..d84bac2 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsFile.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.extapi.psi.PsiFileBase; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.psi.FileViewProvider; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.filetype.RequirementsFileType; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.lang.RequirementsLanguage; +import org.jetbrains.annotations.NotNull; + +public class RequirementsFile extends PsiFileBase { + + public RequirementsFile(@NotNull FileViewProvider viewProvider) { + super(viewProvider, RequirementsLanguage.INSTANCE); + } + + @NotNull + public FileType getFileType() { + return RequirementsFileType.INSTANCE; + } + + @NotNull + public String toString() { + return "Requirements File"; + } +} diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsParserDefinition.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsParserDefinition.java new file mode 100644 index 0000000..3f41154 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsParserDefinition.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.lang.ASTNode; +import com.intellij.lang.ParserDefinition; +import com.intellij.lang.PsiParser; +import com.intellij.lexer.Lexer; +import com.intellij.openapi.project.Project; +import com.intellij.psi.FileViewProvider; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.tree.IFileElementType; +import com.intellij.psi.tree.TokenSet; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.lang.RequirementsLanguage; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.lexer.RequirementsLexerAdapter; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.parser.RequirementsParser; +import org.jetbrains.annotations.NotNull; + +import static org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi.RequirementsTokenSets.COMMENTS; + +public class RequirementsParserDefinition implements ParserDefinition { + + private static final IFileElementType FILE = new IFileElementType(RequirementsLanguage.INSTANCE); + + @Override + public @NotNull Lexer createLexer(Project project) { + return new RequirementsLexerAdapter(); + } + + @Override + public @NotNull PsiParser createParser(Project project) { + return new RequirementsParser(); + } + + @Override + public @NotNull IFileElementType getFileNodeType() { + return FILE; + } + + @Override + public @NotNull TokenSet getCommentTokens() { + return COMMENTS; + } + + @Override + public @NotNull TokenSet getStringLiteralElements() { + return TokenSet.EMPTY; + } + + @Override + public @NotNull PsiElement createElement(ASTNode node) { + return RequirementsTypes.Factory.createElement(node); + } + + @Override + public @NotNull PsiFile createFile(@NotNull FileViewProvider viewProvider) { + return new RequirementsFile(viewProvider); + } +} diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsTokenSets.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsTokenSets.java new file mode 100644 index 0000000..77ab05f --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsTokenSets.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.tree.TokenSet; + +public interface RequirementsTokenSets { + + TokenSet COMMENTS = TokenSet.create(RequirementsTypes.COMMENT); +} diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsTokenType.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsTokenType.java new file mode 100644 index 0000000..3a9cec2 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/requirements/psi/RequirementsTokenType.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.componentanalysis.pypi.requirements.psi; + +import com.intellij.psi.tree.IElementType; +import org.jboss.tools.intellij.componentanalysis.pypi.requirements.lang.RequirementsLanguage; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + + +public class RequirementsTokenType extends IElementType { + + public RequirementsTokenType(@NonNls @NotNull String debugName) { + super(debugName, RequirementsLanguage.INSTANCE); + } + + @NotNull + public String toString() { + return "RequirementsTokenType." + super.toString(); + } +} + diff --git a/src/main/java/org/jboss/tools/intellij/exhort/ApiService.java b/src/main/java/org/jboss/tools/intellij/exhort/ApiService.java index e9e627b..16b9ddf 100644 --- a/src/main/java/org/jboss/tools/intellij/exhort/ApiService.java +++ b/src/main/java/org/jboss/tools/intellij/exhort/ApiService.java @@ -81,7 +81,7 @@ public AnalysisReport getComponentAnalysis(final String packageManager, final St try { ApiSettingsState.getInstance().setApiOptions(); CompletableFuture componentReport; - if ("go.mod".equals(manifestName)) { + if ("go.mod".equals(manifestName) || "requirements.txt".equals(manifestName)) { var manifestContent = Files.readAllBytes(Paths.get(manifestPath)); componentReport = exhortApi.componentAnalysis(manifestName, manifestContent); } else { diff --git a/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsComponent.java b/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsComponent.java index 3db43df..e3c75f2 100644 --- a/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsComponent.java +++ b/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsComponent.java @@ -33,6 +33,12 @@ public class ApiSettingsComponent { + "
Specifies absolute path of the directory containing node executable."; private final static String goPathLabel = "Go > Executable: Path" + "
Specifies absolute path of go executable."; + private final static String pythonPathLabel = "Python > Executable: Path" + + "
Specifies absolute path of python executable."; + private final static String pipPathLabel = "Pip > Executable: Path" + + "
Specifies absolute path of pip executable."; + private final static String usePython2Label = "Python > Executable: Version"; + private final static String usePythonVirtualEnvLabel = "Python > Virtual Envrionment"; private final static String snykTokenLabel = "Red Hat Dependency Analytics: Exhort Snyk Token" + "
Red Hat Dependency Analytics sever authentication token for Snyk."; @@ -43,6 +49,10 @@ public class ApiSettingsComponent { private final TextFieldWithBrowseButton npmPathText; private final TextFieldWithBrowseButton nodePathText; private final TextFieldWithBrowseButton goPathText; + private final TextFieldWithBrowseButton pythonPathText; + private final TextFieldWithBrowseButton pipPathText; + private final JCheckBox usePython2Check; + private final JCheckBox usePythonVirtualEnvCheck; private final JBTextField snykTokenText; public ApiSettingsComponent() { @@ -55,7 +65,7 @@ public ApiSettingsComponent() { TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT ); - javaPathText= new TextFieldWithBrowseButton(); + javaPathText = new TextFieldWithBrowseButton(); javaPathText.addBrowseFolderListener( null, null, @@ -91,6 +101,28 @@ public ApiSettingsComponent() { TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT ); + pythonPathText = new TextFieldWithBrowseButton(); + pythonPathText.addBrowseFolderListener( + null, + null, + null, + FileChooserDescriptorFactory.createSingleFileDescriptor(), + TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT + ); + + pipPathText = new TextFieldWithBrowseButton(); + pipPathText.addBrowseFolderListener( + null, + null, + null, + FileChooserDescriptorFactory.createSingleFileDescriptor(), + TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT + ); + + usePython2Check = new JCheckBox("Use python 2.x"); + + usePythonVirtualEnvCheck = new JCheckBox("Use python virtual environment"); + snykTokenText = new JBTextField(); mainPanel = FormBuilder.createFormBuilder() @@ -107,6 +139,15 @@ public ApiSettingsComponent() { .addLabeledComponent(new JBLabel(goPathLabel), goPathText, 1, true) .addSeparator(10) .addVerticalGap(10) + .addLabeledComponent(new JBLabel(pythonPathLabel), pythonPathText, 1, true) + .addVerticalGap(10) + .addLabeledComponent(new JBLabel(pipPathLabel), pipPathText, 1, true) + .addVerticalGap(10) + .addLabeledComponent(new JBLabel(usePython2Label), usePython2Check, 1, true) + .addVerticalGap(10) + .addLabeledComponent(new JBLabel(usePythonVirtualEnvLabel), usePythonVirtualEnvCheck, 1, true) + .addSeparator(10) + .addVerticalGap(10) .addLabeledComponent(new JBLabel(snykTokenLabel), snykTokenText, 1, true) .addComponentFillVertically(new JPanel(), 0) .getPanel(); @@ -165,6 +206,40 @@ public void setGoPathText(@NotNull String text) { goPathText.setText(text); } + @NotNull + public String getPythonPathText() { + return pythonPathText.getText(); + } + + public void setPythonPathText(@NotNull String text) { + pythonPathText.setText(text); + } + + @NotNull + public String getPipPathText() { + return pipPathText.getText(); + } + + public void setPipPathText(@NotNull String text) { + pipPathText.setText(text); + } + + public boolean getUsePython2Check() { + return usePython2Check.isSelected(); + } + + public void setUsePython2Check(boolean selected) { + usePython2Check.setSelected(selected); + } + + public boolean getUsePythonVirtualEnvCheck() { + return usePythonVirtualEnvCheck.isSelected(); + } + + public void setUsePythonVirtualEnvCheck(boolean selected) { + usePythonVirtualEnvCheck.setSelected(selected); + } + @NotNull public String getSnykTokenText() { return snykTokenText.getText(); diff --git a/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsConfigurable.java b/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsConfigurable.java index dd2fff4..1ad5613 100644 --- a/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsConfigurable.java +++ b/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsConfigurable.java @@ -44,6 +44,10 @@ public boolean isModified() { modified |= !settingsComponent.getNpmPathText().equals(settings.npmPath); modified |= !settingsComponent.getNodePathText().equals(settings.nodePath); modified |= !settingsComponent.getGoPathText().equals(settings.goPath); + modified |= !settingsComponent.getPythonPathText().equals(settings.pythonPath); + modified |= !settingsComponent.getPipPathText().equals(settings.pipPath); + modified |= settingsComponent.getUsePython2Check() != settings.usePython2; + modified |= settingsComponent.getUsePythonVirtualEnvCheck() != settings.usePythonVirtualEnv; modified |= !settingsComponent.getSnykTokenText().equals(settings.snykToken); return modified; } @@ -56,6 +60,10 @@ public void apply() { settings.npmPath = settingsComponent.getNpmPathText(); settings.nodePath = settingsComponent.getNodePathText(); settings.goPath = settingsComponent.getGoPathText(); + settings.pythonPath = settingsComponent.getPythonPathText(); + settings.pipPath = settingsComponent.getPipPathText(); + settings.usePython2 = settingsComponent.getUsePython2Check(); + settings.usePythonVirtualEnv = settingsComponent.getUsePythonVirtualEnvCheck(); settings.snykToken = settingsComponent.getSnykTokenText(); } @@ -67,6 +75,10 @@ public void reset() { settingsComponent.setNpmPathText(settings.npmPath != null ? settings.npmPath : ""); settingsComponent.setNodePathText(settings.nodePath != null ? settings.nodePath : ""); settingsComponent.setGoPathText(settings.goPath != null ? settings.goPath : ""); + settingsComponent.setPythonPathText(settings.pythonPath != null ? settings.pythonPath : ""); + settingsComponent.setPipPathText(settings.pipPath != null ? settings.pipPath : ""); + settingsComponent.setUsePython2Check(settings.usePython2); + settingsComponent.setUsePythonVirtualEnvCheck(settings.usePythonVirtualEnv); settingsComponent.setSnykTokenText(settings.snykToken != null ? settings.snykToken : ""); } diff --git a/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsState.java b/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsState.java index 73e798c..20b11e9 100644 --- a/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsState.java +++ b/src/main/java/org/jboss/tools/intellij/settings/ApiSettingsState.java @@ -36,6 +36,11 @@ public static ApiSettingsState getInstance() { public String npmPath; public String nodePath; public String goPath; + public String pythonPath; + public String pipPath; + public boolean usePython2; + public boolean usePythonVirtualEnv; + public String snykToken; @Override @@ -74,6 +79,38 @@ public void setApiOptions() { } else { System.clearProperty("EXHORT_GO_PATH"); } + if (usePython2) { + if (pythonPath != null && !pythonPath.isBlank()) { + System.setProperty("EXHORT_PYTHON_PATH", pythonPath); + } else { + System.clearProperty("EXHORT_PYTHON_PATH"); + } + if (pipPath != null && !pipPath.isBlank()) { + System.setProperty("EXHORT_PIP_PATH", pipPath); + } else { + System.clearProperty("EXHORT_PIP_PATH"); + } + System.clearProperty("EXHORT_PYTHON3_PATH"); + System.clearProperty("EXHORT_PIP3_PATH"); + } else { + if (pythonPath != null && !pythonPath.isBlank()) { + System.setProperty("EXHORT_PYTHON3_PATH", pythonPath); + } else { + System.clearProperty("EXHORT_PYTHON3_PATH"); + } + if (pipPath != null && !pipPath.isBlank()) { + System.setProperty("EXHORT_PIP3_PATH", pipPath); + } else { + System.clearProperty("EXHORT_PIP3_PATH"); + } + System.clearProperty("EXHORT_PYTHON_PATH"); + System.clearProperty("EXHORT_PIP_PATH"); + } + if (usePythonVirtualEnv) { + System.setProperty("EXHORT_PYTHON_VIRTUAL_ENV", "true"); + } else { + System.clearProperty("EXHORT_PYTHON_VIRTUAL_ENV"); + } if (snykToken != null && !snykToken.isBlank()) { System.setProperty("EXHORT_SNYK_TOKEN", snykToken); } else { diff --git a/src/main/java/org/jboss/tools/intellij/stackanalysis/SaAction.java b/src/main/java/org/jboss/tools/intellij/stackanalysis/SaAction.java index 9190c55..e885c3e 100644 --- a/src/main/java/org/jboss/tools/intellij/stackanalysis/SaAction.java +++ b/src/main/java/org/jboss/tools/intellij/stackanalysis/SaAction.java @@ -32,9 +32,8 @@ public class SaAction extends AnAction { private static final List supportedManifestFiles = Arrays.asList( "pom.xml", "package.json", - "go.mod" -// Disable support for go and python -// "requirements.txt", "requirements-dev.txt" + "go.mod", + "requirements.txt" ); public SaAction() { diff --git a/src/main/java/org/jboss/tools/intellij/stackanalysis/SaUtils.java b/src/main/java/org/jboss/tools/intellij/stackanalysis/SaUtils.java index a8f0136..1e86635 100644 --- a/src/main/java/org/jboss/tools/intellij/stackanalysis/SaUtils.java +++ b/src/main/java/org/jboss/tools/intellij/stackanalysis/SaUtils.java @@ -82,7 +82,7 @@ private JsonObject closeCustomEditor(FileEditorManager instance, JsonObject mani for (VirtualFile openFile : openFiles) { // Check if opened file extension is sa, and existing tab manifest file type is same as new (pom.xml, go.mod) // if not then no need to close any existing tab, just create new tab. - if (openFile.getExtension().equals("sa") + if ("sa".equals(openFile.getExtension()) && openFile.getNameWithoutExtension() .replaceAll("^.*?_", "") .equals(manifestDetails.get("manifestName").getAsString())) { @@ -117,7 +117,8 @@ public JsonObject performSA(VirtualFile manifestFile) { String reportLink; if ("pom.xml".equals(manifestFile.getName()) || "package.json".equals(manifestFile.getName()) - || "go.mod".equals(manifestFile.getName())) { + || "go.mod".equals(manifestFile.getName()) + || "requirements.txt".equals(manifestFile.getName())) { ApiService apiService = ServiceManager.getService(ApiService.class); reportLink = apiService.getStackAnalysis( determinePackageManagerName(manifestFile.getName()), @@ -151,6 +152,9 @@ private String determinePackageManagerName(String name) { case "go.mod": packageManager = "go"; break; + case "requirements.txt": + packageManager = "python"; + break; default: throw new IllegalArgumentException("package manager not implemented"); } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index cd6ce6d..066888b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -329,6 +329,20 @@ implementationClass="org.jboss.tools.intellij.componentanalysis.npm.NpmCAInspection"/> + + + + + + diff --git a/src/main/resources/inspectionDescriptions/PipCAInspection.html b/src/main/resources/inspectionDescriptions/PipCAInspection.html new file mode 100644 index 0000000..c08bc90 --- /dev/null +++ b/src/main/resources/inspectionDescriptions/PipCAInspection.html @@ -0,0 +1,8 @@ + + +Reports dependencies vulnerabilities in requirements.txt files. +

+ Powered by Snyk. +

+ + \ No newline at end of file