// Starts the verify swing worker protected void verify() { getProgressPanel().setIndeterminate(true); getProgressPanel().setText("Verifying downloads..."); Verifier verifier = new Verifier(getMd5Map()); verifier.addPropertyChangeListener(this); verifier.execute(); }
/** * Slightly modifies the behaviour of the phases based on what the caller really needs. Some * invocations of the compilation infrastructure don't need the bytecode, so we can skip creating * it, they would rather have a more 'source like' AST. * * @param isReconcile is this a reconciling compile? */ public void tweak(boolean isReconcile) { // Cant do this for field initializers. They need to be in the constructor in order for them to // be correctly visited by the verifier and have certain optimizations performed (creating // returns) if (isReconcile) { verifier.inlineStaticFieldInitializersIntoClinit = false; // verifier.inlineFieldInitializersIntoInit=false; staticImportVisitor.isReconcile = true; } else { verifier.inlineStaticFieldInitializersIntoClinit = true; // verifier.inlineFieldInitializersIntoInit=true; } this.isReconcile = isReconcile; }
/** * This will set a pseudo attribute with the given name and value. If the PI data is not already * in a pseudo-attribute format, this will replace the existing data. * * @param name <code>String</code> name of pair. * @param value <code>String</code> value for pair. * @return <code>ProcessingInstruction</code> this PI modified. */ public ProcessingInstruction setPseudoAttribute(String name, String value) { String reason = Verifier.checkProcessingInstructionData(name); if (reason != null) { throw new IllegalDataException(name, reason); } reason = Verifier.checkProcessingInstructionData(value); if (reason != null) { throw new IllegalDataException(value, reason); } this.mapData.put(name, value); this.rawData = toString(mapData); return this; }
/** * Check and add the <code>Attribute</code> to this list at the given index. Note: does not check * for duplicate attributes. * * @param index index where to add <code>Attribute</code> * @param attribute <code>Attribute</code> to add */ void add(int index, Attribute attribute) { if (attribute.getParent() != null) { throw new IllegalAddException( "The attribute already has an existing parent \"" + attribute.getParent().getQualifiedName() + "\""); } String reason = Verifier.checkNamespaceCollision(attribute, parent); if (reason != null) { throw new IllegalAddException(parent, attribute, reason); } if (index < 0 || index > size) { throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size()); } attribute.setParent(parent); ensureCapacity(size + 1); if (index == size) { elementData[size++] = attribute; } else { System.arraycopy(elementData, index, elementData, index + 1, size - index); elementData[index] = attribute; size++; } modCount++; }
/** * This will set the target for the PI. * * @param newTarget <code>String</code> new target of PI. * @return <code>ProcessingInstruction</code> - this PI modified. */ public ProcessingInstruction setTarget(String newTarget) { String reason; if ((reason = Verifier.checkProcessingInstructionTarget(newTarget)) != null) { throw new IllegalTargetException(newTarget, reason); } target = newTarget; return this; }
/** * Adds an RRset to the Cache. * * @param r The RRset to be added * @param cred The credibility of these records * @param o The source of this RRset (this could be a Message, for example) * @see RRset */ public void addRRset(RRset rrset, byte cred) { Name name = rrset.getName(); short type = rrset.getType(); if (verifier != null) rrset.setSecurity(verifier.verify(rrset, this)); if (secure && rrset.getSecurity() < DNSSEC.Secure) return; Element element = (Element) findExactSet(name, type); if (element == null || cred > element.credibility) addSet(name, type, new PositiveElement(rrset, cred)); }
/** * This will set the raw data for the PI. * * @param data <code>String</code> data of PI. * @return <code>ProcessingInstruction</code> - this PI modified. */ public ProcessingInstruction setData(String data) { String reason = Verifier.checkProcessingInstructionData(data); if (reason != null) { throw new IllegalDataException(data, reason); } this.rawData = data; this.mapData = parseData(data); return this; }
/** * This will set the name/value pairs within the passed <code>Map</code> as the pairs for the data * of this PI. The keys should be the pair name and the values should be the pair values. * * @param data new map data to use * @return <code>ProcessingInstruction</code> - modified PI. */ public ProcessingInstruction setData(Map<String, String> data) { String temp = toString(data); String reason = Verifier.checkProcessingInstructionData(temp); if (reason != null) { throw new IllegalDataException(temp, reason); } this.rawData = temp; this.mapData = new LinkedHashMap<String, String>(data); return this; }
// Verification has completed - move to next state private void verifyCompleted(Verifier verifier) { boolean success = false; try { success = verifier.get(); // return true if verify successful } catch (Exception fallThrough) { // } if (success) { // can update CP only without cycling the engine setState(onlyUpdatingControlPanel() ? State.Update : State.StopEngine); } else { showError("Downloaded files failed verification. Update could not complete."); setState(State.Finalise); } }
private void verifyRecords(Cache tcache) { Iterator it; it = tcache.names(); while (it.hasNext()) { Name name = (Name) it.next(); Object[] elements = findExactSets(name); for (int i = 0; i < elements.length; i++) { Element element = (Element) elements[i]; if (element instanceof PositiveElement) continue; RRset rrset = ((PositiveElement) element).rrset; /* for now, ignore negative cache entries */ if (rrset == null) continue; if (verifier != null) rrset.setSecurity(verifier.verify(rrset, this)); if (rrset.getSecurity() < DNSSEC.Secure) continue; addSet(name, rrset.getType(), element); } } }
/** * Set the object at the specified location to the supplied object. Note: does not check for * duplicate attributes. * * @param index The location to set the value to. * @param attribute The attribute to set. * @return The object which was replaced. throws IndexOutOfBoundsException if index < 0 || index * >= size() */ Object set(int index, Attribute attribute) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size()); if (attribute.getParent() != null) { throw new IllegalAddException( "The attribute already has an existing parent \"" + attribute.getParent().getQualifiedName() + "\""); } String reason = Verifier.checkNamespaceCollision(attribute, parent); if (reason != null) { throw new IllegalAddException(parent, attribute, reason); } Attribute old = (Attribute) elementData[index]; old.setParent(null); elementData[index] = attribute; attribute.setParent(parent); return old; }
public void _workspace(WorkspaceOptions opts) throws Exception { File base = bnd.getBase(); String name = opts._arguments().get(0); File workspaceDir = Processor.getFile(base, name); name = workspaceDir.getName(); base = workspaceDir.getParentFile(); if (base == null) { bnd.error( "You cannot create a workspace in the root (%s). The parent of a workspace %n" + "must be a valid directory. Recommended is to dedicate a directory to %n" + "all (or related) workspaces.", workspaceDir); return; } if (!opts.anyname() && !Verifier.isBsn(name)) { bnd.error( "You specified a workspace name that does not follow the recommended pattern " + "(it should be like a Bundle Symbolic name). It is a bit pedantic but it " + "really helps hwne you get many workspaces. If you insist on this name, use the -a/--anyname option."); return; } Workspace ws = bnd.getWorkspace((File) null); if (ws != null && ws.isValid()) { bnd.error( "You are currently in a workspace already (%s) in %s. You can only create a new workspace outside an existing workspace", ws, base); return; } File eclipseDir = workspaceDir; workspaceDir.mkdirs(); if (!opts.single()) workspaceDir = new File(workspaceDir, "scm"); workspaceDir.mkdirs(); if (!base.isDirectory()) { bnd.error("Could not create directory for the bnd workspace %s", base); } else if (!eclipseDir.isDirectory()) { bnd.error("Could not create directory for the Eclipse workspace %s", eclipseDir); } if (!workspaceDir.isDirectory()) { bnd.error("Could not create the workspace directory %s", workspaceDir); return; } if (!opts.update() && !opts.force() && workspaceDir.list().length > 0) { bnd.error( "The workspace directory %s is not empty, specify -u/--update to update or -f/--force to replace", workspaceDir); } InputStream in = getClass().getResourceAsStream("/templates/enroute.zip"); if (in == null) { bnd.error("Cannot find template in this jar %s", "/templates/enroute.zip"); return; } Pattern glob = Pattern.compile("[^/]+|cnf/.*|\\...+/.*"); copy(workspaceDir, in, glob, opts.force()); File readme = new File(workspaceDir, "README.md"); if (readme.isFile()) IO.copy(readme, bnd.out); bnd.out.printf( "%nWorkspace %s created.%n%n" // + " Start Eclipse:%n" // + " 1) Select the Eclipse workspace %s%n" // + " 2) Package Explorer context menu: Import/General/Existing Projects from %s%n" + "%n" + "", // workspaceDir.getName(), eclipseDir, workspaceDir); }
/** * Entity Bean's ejbPostCreate(...) methods test. Each entity Bean class may define zero or more * ejbPostCreate(...) methods. The number and signatures of a entity Bean's create methods are * specific to each EJB class. The method signatures must follow these rules: * * <p>The method name must be ejbPostCreate. * * <p>The method must not be declared as static. * * @param descriptor the Enterprise Java Bean deployment descriptor * @return <code>Result</code> the results for this assertion */ public Result check(EjbDescriptor descriptor) { Result result = getInitializedResult(); ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); if (descriptor instanceof EjbEntityDescriptor) { boolean oneFailed = false; int foundAtLeastOne = 0; try { Context context = getVerifierContext(); ClassLoader jcl = context.getClassLoader(); Class c = Class.forName( descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); boolean ejbPostCreateFound = false; boolean isStatic = false; // start do while loop here.... do { Method[] methods = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { // reset flags from last time thru loop ejbPostCreateFound = false; isStatic = false; // The method name must be ejbPostCreate. if (methods[i].getName().startsWith("ejbPostCreate")) { foundAtLeastOne++; ejbPostCreateFound = true; // The method must not be declared as final or static. int modifiers = methods[i].getModifiers(); if (Modifier.isStatic(modifiers)) { isStatic = true; } // now display the appropriate results for this particular // ejbPostCreate method if (ejbPostCreateFound && (!isStatic)) { result.addGoodDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.addGoodDetails( smh.getLocalString( getClass().getName() + ".debug1", "For EJB Class [ {0} ] method [ {1} ]", new Object[] {descriptor.getEjbClassName(), methods[i].getName()})); result.addGoodDetails( smh.getLocalString( getClass().getName() + ".passed", "[ {0} ] properly declares non-static [ {1} ] method.", new Object[] {descriptor.getEjbClassName(), methods[i].getName()})); } else if (ejbPostCreateFound && isStatic) { oneFailed = true; result.addErrorDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.addErrorDetails( smh.getLocalString( getClass().getName() + ".debug1", "For EJB Class [ {0} ] ejbPostCreate(...) Method [ {1} ]", new Object[] {descriptor.getEjbClassName(), methods[i].getName()})); result.addErrorDetails( smh.getLocalString( getClass().getName() + ".failed", "Error: A static [ {0} ] method was found, but [ {1} ] cannot be declared as static.", new Object[] {methods[i].getName(), methods[i].getName()})); } } } } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0)); if (foundAtLeastOne == 0) { result.addNaDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.notApplicable( smh.getLocalString( getClass().getName() + ".notApplicable1", "[ {0} ] does not declare any ejbPostCreate(...) methods.", new Object[] {descriptor.getEjbClassName()})); } } catch (ClassNotFoundException e) { Verifier.debug(e); result.addErrorDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.failed( smh.getLocalString( getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] {descriptor.getEjbClassName()})); oneFailed = true; } if (oneFailed) { result.setStatus(result.FAILED); } else if (foundAtLeastOne == 0) { result.setStatus(result.NOT_APPLICABLE); } else { result.setStatus(result.PASSED); } return result; } else { result.addNaDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.notApplicable( smh.getLocalString( getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] {getClass(), "Entity", "Session"})); return result; } }
/** * The alt-dd element specifies a URI to the post-assembly deployment descriptor relative to the * root of the application * * @param descriptor the Application deployment descriptor * @return <code>Result</code> the results for this assertion */ public Result check(Application descriptor) { Result result = getInitializedResult(); if (descriptor.getEjbBundleDescriptors().size() > 0) { boolean oneFailed = false; int na = 0; for (Iterator itr = descriptor.getEjbBundleDescriptors().iterator(); itr.hasNext(); ) { EjbBundleDescriptor ejbd = (EjbBundleDescriptor) itr.next(); if (ejbd.getModuleDescriptor().getAlternateDescriptor() != null) { if (!(ejbd.getModuleDescriptor().getAlternateDescriptor().equals(""))) { JarFile jarFile = null; InputStream deploymentEntry = null; // File f = null; // if (Verifier.getEarFile() != null) // f = new File(Verifier.getEarFile()); try { // if (f==null){ String uri = getAbstractArchiveUri(descriptor); // try { FileArchive arch = new FileArchive(); arch.open(uri); deploymentEntry = arch.getEntry(ejbd.getModuleDescriptor().getAlternateDescriptor()); // }catch (Exception e) { } // }else{ // // jarFile = new JarFile(f); // ZipEntry deploymentEntry1 = // jarFile.getEntry(ejbd.getModuleDescriptor().getAlternateDescriptor()); // if (deploymentEntry1 != null){ // deploymentEntry = // jarFile.getInputStream(deploymentEntry1); // } // } if (deploymentEntry != null) { result.addGoodDetails( smh.getLocalString( getClass().getName() + ".passed", "Found alternate EJB deployment descriptor URI file [ {0} ] within [ {1} ]", new Object[] { ejbd.getModuleDescriptor().getAlternateDescriptor(), ejbd.getName() })); } else { if (!oneFailed) { oneFailed = true; } result.addErrorDetails( smh.getLocalString( getClass().getName() + ".failed", "Error: No alternate EJB deployment descriptor URI file found, looking for [ {0} ] within [ {1} ]", new Object[] { ejbd.getModuleDescriptor().getAlternateDescriptor(), ejbd.getName() })); } // jarFile.close(); } catch (FileNotFoundException ex) { Verifier.debug(ex); if (!oneFailed) { oneFailed = true; } result.failed( smh.getLocalString( getClass().getName() + ".failedException", "Error: File not found trying to read deployment descriptor file [ {0} ] within [ {1} ]", new Object[] { ejbd.getModuleDescriptor().getAlternateDescriptor(), ejbd.getName() })); } catch (IOException ex) { Verifier.debug(ex); if (!oneFailed) { oneFailed = true; } result.failed( smh.getLocalString( getClass().getName() + ".failedException1", "Error: IO Error trying to read deployment descriptor file [ {0} ] within [ {1} ]", new Object[] { ejbd.getModuleDescriptor().getAlternateDescriptor(), ejbd.getName() })); } finally { try { if (deploymentEntry != null) deploymentEntry.close(); } catch (Exception x) { } } } } else { na++; result.notApplicable( smh.getLocalString( getClass().getName() + ".notApplicable1", "There is no java EJB alternative deployment descriptor in [ {0} ]", new Object[] {ejbd.getName()})); } } if (oneFailed) { result.setStatus(Result.FAILED); } else if (na == descriptor.getEjbBundleDescriptors().size()) { result.setStatus(Result.NOT_APPLICABLE); } else { result.setStatus(Result.PASSED); } } else { result.notApplicable( smh.getLocalString( getClass().getName() + ".notApplicable", "There are no EJB components in application [ {0} ]", new Object[] {descriptor.getName()})); } return result; }
/** * Define ejbFindByPrimaryKey method arguments test. * * <p>Every entity enterprise Bean class must define the ejbFindByPrimaryKey method. * * <p>The methods arguments types must be legal types for RMI-IIOP. * * @param descriptor the Enterprise Java Bean deployment descriptor * @return <code>Result</code> the results for this assertion */ public Result check(EjbDescriptor descriptor) { Result result = getInitializedResult(); ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); if (descriptor instanceof EjbEntityDescriptor) { String persistentType = ((EjbEntityDescriptor) descriptor).getPersistenceType(); if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistentType)) { Class[] ejbFinderMethodParameterTypes; boolean ejbFindByPrimaryKeyMethodFound = false; boolean oneFailed = false; boolean isLegalRMIIIOP = false; try { // retrieve the EJB Class Methods Context context = getVerifierContext(); ClassLoader jcl = context.getClassLoader(); Class EJBClass = Class.forName( descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); // start do while loop here.... do { Method[] ejbFinderMethods = EJBClass.getDeclaredMethods(); for (int j = 0; j < ejbFinderMethods.length; ++j) { if (ejbFinderMethods[j].getName().equals("ejbFindByPrimaryKey")) { // Every entity enterprise Bean class must define the // ejbFindByPrimaryKey method. ejbFindByPrimaryKeyMethodFound = true; // The methods arguments types must be legal types for RMI-IIOP. ejbFinderMethodParameterTypes = ejbFinderMethods[j].getParameterTypes(); if (RmiIIOPUtils.isValidRmiIIOPParameters(ejbFinderMethodParameterTypes)) { // these method parameters are valid, continue isLegalRMIIIOP = true; } if (ejbFindByPrimaryKeyMethodFound && isLegalRMIIIOP) { result.addGoodDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.addGoodDetails( smh.getLocalString( getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] {EJBClass.getName(), ejbFinderMethods[j].getName()})); result.addGoodDetails( smh.getLocalString( getClass().getName() + ".passed", "An [ {0} ] method with valid RMI-IIOP argument types was found.", new Object[] {ejbFinderMethods[j].getName()})); } else if (ejbFindByPrimaryKeyMethodFound && (!isLegalRMIIIOP)) { oneFailed = true; result.addErrorDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.addErrorDetails( smh.getLocalString( getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] {EJBClass.getName(), ejbFinderMethods[j].getName()})); result.addErrorDetails( smh.getLocalString( getClass().getName() + ".failed", "Error: An [ {0} ] method was found, but [ {1} ] method has illegal parameter values. [ {2} ] methods arguments types must be legal types for RMI-IIOP.", new Object[] { ejbFinderMethods[j].getName(), ejbFinderMethods[j].getName(), ejbFinderMethods[j].getName() })); } // found one, and there should only be one, break out break; } } } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!ejbFindByPrimaryKeyMethodFound)); if (!ejbFindByPrimaryKeyMethodFound) { oneFailed = true; result.addErrorDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.addErrorDetails( smh.getLocalString( getClass().getName() + ".debug3", "For EJB Class [ {0} ]", new Object[] {descriptor.getEjbClassName()})); result.addErrorDetails( smh.getLocalString( getClass().getName() + ".failed1", "Error: No ejbFindByPrimaryKey method was found in bean class.")); } } catch (ClassNotFoundException e) { Verifier.debug(e); result.addErrorDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.failed( smh.getLocalString( getClass().getName() + ".failedException", "Error: EJB Class [ {0} ] does not exist or is not loadable.", new Object[] {descriptor.getEjbClassName()})); oneFailed = true; } if (oneFailed) { result.setStatus(result.FAILED); } else { result.setStatus(result.PASSED); } } else { // (CONTAINER_PERSISTENCE.equals(persistentType)) result.addNaDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.notApplicable( smh.getLocalString( getClass().getName() + ".notApplicable2", "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistentType })); } return result; } else { result.addNaDetails( smh.getLocalString( "tests.componentNameConstructor", "For [ {0} ]", new Object[] {compName.toString()})); result.notApplicable( smh.getLocalString( getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] {getClass(), "Entity", "Session"})); return result; } }
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { optimizer.visitClass( classNode, source); // GROOVY-4272: repositioned it here from staticImport if (!classNode.isSynthetic()) { GenericsVisitor genericsVisitor = new GenericsVisitor(source); genericsVisitor.visitClass(classNode); } // // Run the Verifier on the outer class // try { verifier.visitClass(classNode); } catch (GroovyRuntimeException rpe) { ASTNode node = rpe.getNode(); getErrorCollector() .addError( new SyntaxException( rpe.getMessage(), node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source); } LabelVerifier lv = new LabelVerifier(source); lv.visitClass(classNode); ClassCompletionVerifier completionVerifier = new ClassCompletionVerifier(source); completionVerifier.visitClass(classNode); ExtendedVerifier xverifier = new ExtendedVerifier(source); xverifier.visitClass(classNode); // because the class may be generated even if a error was found // and that class may have an invalid format we fail here if needed getErrorCollector().failIfErrors(); // // Prep the generator machinery // ClassVisitor visitor = createClassVisitor(); String sourceName = (source == null ? classNode.getModule().getDescription() : source.getName()); // only show the file name and its extension like javac does in its stacktraces rather // than the full path // also takes care of both \ and / depending on the host compiling environment if (sourceName != null) sourceName = sourceName.substring( Math.max(sourceName.lastIndexOf('\\'), sourceName.lastIndexOf('/')) + 1); AsmClassGenerator generator = new AsmClassGenerator(source, context, visitor, sourceName); // // Run the generation and create the class (if required) // // GRECLIPSE: if there are errors, don't generate code. // code gen can fail unexpectedly if there was an earlier error. if (!source.getErrorCollector().hasErrors()) { // end generator.visitClass(classNode); byte[] bytes = ((ClassWriter) visitor).toByteArray(); /// GRECLIPSE: start: added classNode, sourceUnit /*old{ generatedClasses.add(new GroovyClass(classNode.getName(), bytes)); }*/ // newcode generatedClasses.add(new GroovyClass(classNode.getName(), bytes, classNode, source)); // end // // Handle any callback that's been set // if (CompilationUnit.this.classgenCallback != null) { classgenCallback.call(visitor, classNode); } // // Recurse for inner classes // LinkedList innerClasses = generator.getInnerClasses(); while (!innerClasses.isEmpty()) { classgen.call(source, context, (ClassNode) innerClasses.removeFirst()); } // GRECLIPSE: if there are errors, don't generate code } // end }