idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
11,300 | public void addData ( String key , String value ) throws InvalidPackageRevisionDataException { validateDataKey ( key ) ; data . put ( key , value ) ; } | Adds additional data related to the package revision |
11,301 | public void addPipeline ( String groupName , PipelineConfig pipelineConfig ) { groups . addPipeline ( groupName , pipelineConfig ) ; } | when adding pipelines groups or environments we must make sure that both merged and basic scopes are updated |
11,302 | List < ScmMaterialConfig > getScmMaterials ( ) { List < ScmMaterialConfig > scmMaterials = new ArrayList < > ( ) ; for ( FanInNode node : nodes . values ( ) ) { if ( node . materialConfig instanceof ScmMaterialConfig ) { scmMaterials . add ( ( ScmMaterialConfig ) node . materialConfig ) ; } } return scmMaterials ; } | Used in test Only |
11,303 | public TaskConfigProperty addProperty ( String propertyName ) { TaskConfigProperty property = new TaskConfigProperty ( propertyName ) ; add ( property ) ; return property ; } | Adds a property to the configuration of this task . |
11,304 | private void populatePlaceHolderStages ( PipelineInstanceModel pipeline ) { StageInstanceModels stageHistory = pipeline . getStageHistory ( ) ; String pipelineName = pipeline . getName ( ) ; appendFollowingStagesFromConfig ( pipelineName , stageHistory ) ; } | we need placeholder stage for unscheduled stages in pipeline so we can trigger it |
11,305 | public String getUploadUrlOfAgent ( JobIdentifier jobIdentifier , String filePath , int attempt ) { return format ( "%s/%s/%s/%s?attempt=%d&buildId=%d" , baseRemotingURL , "remoting" , "files" , jobIdentifier . artifactLocator ( filePath ) , attempt , jobIdentifier . getBuildId ( ) ) ; } | and therefore cannot locate job correctly when it is rescheduled |
11,306 | public Stage rerunStage ( String pipelineName , Integer pipelineCounter , String stageName , HttpOperationResult result ) { String identifier = StringUtils . join ( Arrays . asList ( pipelineName , pipelineCounter , stageName ) , "/" ) ; HealthStateType healthStateType = HealthStateType . general ( HealthStateScope . forStage ( pipelineName , stageName ) ) ; Stage stage = null ; try { stage = rerunStage ( pipelineName , pipelineCounter , stageName , new ResultUpdatingErrorHandler ( result ) ) ; if ( result . isSuccess ( ) ) { result . accepted ( String . format ( "Request to schedule stage %s accepted" , identifier ) , "" , healthStateType ) ; } } catch ( RuntimeException e ) { if ( result . isSuccess ( ) ) { String message = String . format ( "Stage rerun request for stage [%s] could not be completed " + "because of an unexpected failure. Cause: %s" , identifier , e . getMessage ( ) ) ; LOGGER . error ( message , e ) ; result . internalServerError ( message , healthStateType ) ; } } return stage ; } | Top - level operation only ; consumes exceptions |
11,307 | private boolean isStageActive ( Pipeline pipeline , StageConfig nextStage ) { return stageDao . isStageActive ( pipeline . getName ( ) , CaseInsensitiveString . str ( nextStage . name ( ) ) ) ; } | this method checks if specified stage is active in all pipelines |
11,308 | private synchronized Stage persistStage ( Pipeline pipeline , Stage stage ) { long pipelineId = pipeline . getId ( ) ; stage . setOrderId ( resolveStageOrder ( pipelineId , stage . getName ( ) ) ) ; Stage savedStage = stageDao . save ( pipeline , stage ) ; savedStage . setIdentifier ( new StageIdentifier ( pipeline . getName ( ) , pipeline . getCounter ( ) , pipeline . getLabel ( ) , stage . getName ( ) , String . valueOf ( stage . getCounter ( ) ) ) ) ; for ( JobInstance jobInstance : savedStage . getJobInstances ( ) ) { jobInstance . setIdentifier ( new JobIdentifier ( pipeline , savedStage , jobInstance ) ) ; } return savedStage ; } | need to synchronize this method call to make sure no concurrent issues . |
11,309 | private Integer resolveStageOrder ( long pipelineId , String stageName ) { Integer order = getStageOrderInPipeline ( pipelineId , stageName ) ; if ( order == null ) { order = getMaxStageOrderInPipeline ( pipelineId ) + 1 ; } return order ; } | stage order in current pipeline by 1 as current stage s order |
11,310 | final public < T > Property with ( Option < T > option , T value ) { if ( value != null ) { options . addOrSet ( option , value ) ; } return this ; } | Adds an option |
11,311 | public Property get ( String key ) { for ( Property property : properties ) { if ( property . getKey ( ) . equals ( key ) ) { return property ; } } return null ; } | Gets property for a given property key |
11,312 | protected static boolean matchPath ( String pattern , String str , boolean isCaseSensitive ) { return SelectorUtils . matchPath ( pattern , str , isCaseSensitive ) ; } | Test whether or not a given path matches a given pattern . |
11,313 | public static boolean addDefaultExclude ( String s ) { if ( defaultExcludes . indexOf ( s ) == - 1 ) { defaultExcludes . add ( s ) ; return true ; } return false ; } | Add a pattern to the default excludes unless it is already a default exclude . |
11,314 | public static void resetDefaultExcludes ( ) { defaultExcludes = new Vector ( ) ; for ( int i = 0 ; i < DEFAULTEXCLUDES . length ; i ++ ) { defaultExcludes . add ( DEFAULTEXCLUDES [ i ] ) ; } } | Go back to the hardwired default exclude patterns . |
11,315 | public DirectoryScanner scan ( ) throws IllegalStateException { synchronized ( scanLock ) { if ( scanning ) { while ( scanning ) { try { scanLock . wait ( ) ; } catch ( InterruptedException e ) { continue ; } } if ( illegal != null ) { throw illegal ; } return this ; } scanning = true ; } try { synchronized ( this ) { illegal = null ; clearResults ( ) ; boolean nullIncludes = ( includes == null ) ; includes = nullIncludes ? new String [ ] { "**" } : includes ; boolean nullExcludes = ( excludes == null ) ; excludes = nullExcludes ? new String [ 0 ] : excludes ; if ( basedir == null ) { if ( nullIncludes ) { return this ; } } else { if ( ! basedir . exists ( ) ) { if ( errorOnMissingDir ) { illegal = new IllegalStateException ( "basedir " + basedir + " does not exist" ) ; } else { return this ; } } if ( ! basedir . isDirectory ( ) ) { illegal = new IllegalStateException ( "basedir " + basedir + " is not a directory" ) ; } if ( illegal != null ) { throw illegal ; } } if ( isIncluded ( "" ) ) { if ( ! isExcluded ( "" ) ) { if ( isSelected ( "" , basedir ) ) { dirsIncluded . addElement ( "" ) ; } else { dirsDeselected . addElement ( "" ) ; } } else { dirsExcluded . addElement ( "" ) ; } } else { dirsNotIncluded . addElement ( "" ) ; } checkIncludePatterns ( ) ; clearCaches ( ) ; includes = nullIncludes ? null : includes ; excludes = nullExcludes ? null : excludes ; } } finally { synchronized ( scanLock ) { scanning = false ; scanLock . notifyAll ( ) ; } } return this ; } | Scan for files which match at least one include pattern and don t match any exclude patterns . If there are selectors then the files must pass muster there as well . Scans under basedir if set ; otherwise the include patterns without leading wildcards specify the absolute paths of the files that may be included . |
11,316 | protected synchronized void clearResults ( ) { filesIncluded = new Vector ( ) ; filesNotIncluded = new Vector ( ) ; filesExcluded = new Vector ( ) ; filesDeselected = new Vector ( ) ; dirsIncluded = new Vector ( ) ; dirsNotIncluded = new Vector ( ) ; dirsExcluded = new Vector ( ) ; dirsDeselected = new Vector ( ) ; everythingIncluded = ( basedir != null ) ; scannedDirs . clear ( ) ; } | Clear the result caches for a scan . |
11,317 | protected void scandir ( File dir , String vpath , boolean fast ) { if ( dir == null ) { throw new RuntimeException ( "dir must not be null." ) ; } String [ ] newfiles = dir . list ( ) ; if ( newfiles == null ) { if ( ! dir . exists ( ) ) { throw new RuntimeException ( dir + " doesn't exist." ) ; } else if ( ! dir . isDirectory ( ) ) { throw new RuntimeException ( dir + " is not a directory." ) ; } else { throw new RuntimeException ( "IO error scanning directory '" + dir . getAbsolutePath ( ) + "'" ) ; } } scandir ( dir , vpath , fast , newfiles ) ; } | Scan the given directory for files and directories . Found files and directories are placed in their respective collections based on the matching of includes excludes and the selectors . When a directory is found it is scanned recursively . |
11,318 | private void accountForIncludedFile ( String name , File file ) { processIncluded ( name , file , filesIncluded , filesExcluded , filesDeselected ) ; } | Process included file . |
11,319 | private void accountForIncludedDir ( String name , File file , boolean fast ) { processIncluded ( name , file , dirsIncluded , dirsExcluded , dirsDeselected ) ; if ( fast && couldHoldIncluded ( name ) && ! contentsExcluded ( name ) ) { scandir ( file , name + File . separator , fast ) ; } } | Process included directory . |
11,320 | protected boolean isIncluded ( String name ) { ensureNonPatternSetsReady ( ) ; if ( isCaseSensitive ( ) ? includeNonPatterns . contains ( name ) : includeNonPatterns . contains ( name . toUpperCase ( ) ) ) { return true ; } for ( int i = 0 ; i < includePatterns . length ; i ++ ) { if ( matchPath ( includePatterns [ i ] , name , isCaseSensitive ( ) ) ) { return true ; } } return false ; } | Test whether or not a name matches against at least one include pattern . |
11,321 | protected boolean couldHoldIncluded ( String name ) { for ( int i = 0 ; i < includes . length ; i ++ ) { if ( matchPatternStart ( includes [ i ] , name , isCaseSensitive ( ) ) && isMorePowerfulThanExcludes ( name , includes [ i ] ) && isDeeper ( includes [ i ] , name ) ) { return true ; } } return false ; } | Test whether or not a name matches the start of at least one include pattern . |
11,322 | private boolean isDeeper ( String pattern , String name ) { Vector p = SelectorUtils . tokenizePath ( pattern ) ; Vector n = SelectorUtils . tokenizePath ( name ) ; return p . contains ( "**" ) || p . size ( ) > n . size ( ) ; } | Verify that a pattern specifies files deeper than the level of the specified file . |
11,323 | private boolean contentsExcluded ( String name ) { name = ( name . endsWith ( File . separator ) ) ? name : name + File . separator ; for ( int i = 0 ; i < excludes . length ; i ++ ) { String e = excludes [ i ] ; if ( e . endsWith ( "**" ) && SelectorUtils . matchPath ( e . substring ( 0 , e . length ( ) - 2 ) , name , isCaseSensitive ( ) ) ) { return true ; } } return false ; } | Test whether all contents of the specified directory must be excluded . |
11,324 | protected boolean isExcluded ( String name ) { ensureNonPatternSetsReady ( ) ; if ( isCaseSensitive ( ) ? excludeNonPatterns . contains ( name ) : excludeNonPatterns . contains ( name . toUpperCase ( ) ) ) { return true ; } for ( int i = 0 ; i < excludePatterns . length ; i ++ ) { if ( matchPath ( excludePatterns [ i ] , name , isCaseSensitive ( ) ) ) { return true ; } } return false ; } | Test whether or not a name matches against at least one exclude pattern . |
11,325 | public synchronized String [ ] getIncludedFiles ( ) { if ( filesIncluded == null ) { throw new IllegalStateException ( "Must call scan() first" ) ; } String [ ] files = new String [ filesIncluded . size ( ) ] ; filesIncluded . copyInto ( files ) ; Arrays . sort ( files ) ; return files ; } | Return the names of the files which matched at least one of the include patterns and none of the exclude patterns . The names are relative to the base directory . |
11,326 | public synchronized String [ ] getNotIncludedFiles ( ) { slowScan ( ) ; String [ ] files = new String [ filesNotIncluded . size ( ) ] ; filesNotIncluded . copyInto ( files ) ; return files ; } | Return the names of the files which matched none of the include patterns . The names are relative to the base directory . This involves performing a slow scan if one has not already been completed . |
11,327 | public synchronized String [ ] getExcludedFiles ( ) { slowScan ( ) ; String [ ] files = new String [ filesExcluded . size ( ) ] ; filesExcluded . copyInto ( files ) ; return files ; } | Return the names of the files which matched at least one of the include patterns and at least one of the exclude patterns . The names are relative to the base directory . This involves performing a slow scan if one has not already been completed . |
11,328 | public synchronized String [ ] getIncludedDirectories ( ) { if ( dirsIncluded == null ) { throw new IllegalStateException ( "Must call scan() first" ) ; } String [ ] directories = new String [ dirsIncluded . size ( ) ] ; dirsIncluded . copyInto ( directories ) ; Arrays . sort ( directories ) ; return directories ; } | Return the names of the directories which matched at least one of the include patterns and none of the exclude patterns . The names are relative to the base directory . |
11,329 | public synchronized String [ ] getNotIncludedDirectories ( ) { slowScan ( ) ; String [ ] directories = new String [ dirsNotIncluded . size ( ) ] ; dirsNotIncluded . copyInto ( directories ) ; return directories ; } | Return the names of the directories which matched none of the include patterns . The names are relative to the base directory . This involves performing a slow scan if one has not already been completed . |
11,330 | public synchronized String [ ] getExcludedDirectories ( ) { slowScan ( ) ; String [ ] directories = new String [ dirsExcluded . size ( ) ] ; dirsExcluded . copyInto ( directories ) ; return directories ; } | Return the names of the directories which matched at least one of the include patterns and at least one of the exclude patterns . The names are relative to the base directory . This involves performing a slow scan if one has not already been completed . |
11,331 | public synchronized void addDefaultExcludes ( ) { int excludesLength = excludes == null ? 0 : excludes . length ; String [ ] newExcludes ; newExcludes = new String [ excludesLength + defaultExcludes . size ( ) ] ; if ( excludesLength > 0 ) { System . arraycopy ( excludes , 0 , newExcludes , 0 , excludesLength ) ; } String [ ] defaultExcludesTemp = getDefaultExcludes ( ) ; for ( int i = 0 ; i < defaultExcludesTemp . length ; i ++ ) { newExcludes [ i + excludesLength ] = defaultExcludesTemp [ i ] . replace ( '/' , File . separatorChar ) . replace ( '\\' , File . separatorChar ) ; } excludes = newExcludes ; } | Add default exclusions to the current exclusions set . |
11,332 | private String [ ] list ( File file ) { String [ ] files = ( String [ ] ) fileListMap . get ( file ) ; if ( files == null ) { files = file . list ( ) ; if ( files != null ) { fileListMap . put ( file , files ) ; } } return files ; } | Return a cached result of list performed on file if available . Invokes the method and caches the result otherwise . |
11,333 | private synchronized void clearCaches ( ) { fileListMap . clear ( ) ; includeNonPatterns . clear ( ) ; excludeNonPatterns . clear ( ) ; includePatterns = null ; excludePatterns = null ; areNonPatternSetsReady = false ; } | Clear internal caches . |
11,334 | private synchronized void ensureNonPatternSetsReady ( ) { if ( ! areNonPatternSetsReady ) { includePatterns = fillNonPatternSet ( includeNonPatterns , includes ) ; excludePatterns = fillNonPatternSet ( excludeNonPatterns , excludes ) ; areNonPatternSetsReady = true ; } } | Ensure that the in|exclude " ; patterns" ; have been properly divided up . |
11,335 | private String deDuplicatedErrors ( List < ConfigErrors > allErrors ) { Set < String > errors = allErrors . stream ( ) . map ( ConfigErrors :: firstError ) . collect ( Collectors . toSet ( ) ) ; return StringUtils . join ( errors , "," ) ; } | Hack to remove duplicate errors . See AdminRole . addError |
11,336 | public Result withSuccessMessages ( String ... successMessages ) { List < String > msgList = Arrays . asList ( successMessages ) ; return withSuccessMessages ( msgList ) ; } | Creates instance of result with specified success messages |
11,337 | public String getMessagesForDisplay ( ) { if ( messages . isEmpty ( ) ) { return "" ; } StringBuilder stringBuilder = new StringBuilder ( ) ; for ( String message : messages ) { stringBuilder . append ( message ) ; stringBuilder . append ( "\n" ) ; } String tempStr = stringBuilder . toString ( ) ; stringBuilder . deleteCharAt ( tempStr . length ( ) - 1 ) ; return stringBuilder . toString ( ) ; } | Formats the messages in the result to a suitable form so that it can be used in user interface . |
11,338 | private void haltIfEntityWithSameIdExists ( ElasticProfile elasticProfile ) { if ( elasticProfileService . findProfile ( elasticProfile . getId ( ) ) == null ) { return ; } elasticProfile . addError ( "id" , format ( "Elastic profile ids should be unique. Elastic profile with id '%s' already exists." , elasticProfile . getId ( ) ) ) ; throw haltBecauseEntityAlreadyExists ( jsonWriter ( elasticProfile ) , "elasticProfile" , elasticProfile . getId ( ) ) ; } | this is done in command as well keeping it here for early return instead of failing later during config update command . |
11,339 | public static String createBingUrl ( String keyword , int pageIndex ) throws Exception { int first = pageIndex * 10 - 9 ; keyword = URLEncoder . encode ( keyword , "utf-8" ) ; return String . format ( "http://cn.bing.com/search?q=%s&first=%s" , keyword , first ) ; } | construct the Bing Search url by the search keyword and the pageIndex |
11,340 | public CrawlDatum next ( ) { int topN = getConf ( ) . getTopN ( ) ; int maxExecuteCount = getConf ( ) . getOrDefault ( Configuration . KEY_MAX_EXECUTE_COUNT , Integer . MAX_VALUE ) ; if ( topN > 0 && totalGenerate >= topN ) { return null ; } CrawlDatum datum ; while ( true ) { try { datum = nextWithoutFilter ( ) ; if ( datum == null ) { return datum ; } if ( filter == null || ( datum = filter . filter ( datum ) ) != null ) { if ( datum . getExecuteCount ( ) > maxExecuteCount ) { continue ; } totalGenerate += 1 ; return datum ; } } catch ( Exception e ) { LOG . info ( "Exception when generating" , e ) ; return null ; } } } | return null if there is no CrawlDatum to generate |
11,341 | @ SuppressWarnings ( "unchecked" ) public double [ ] placement3DToMatrix ( AbstractHashMapVirtualObject ifcAxis2Placement3D ) { EReference refDirectionFeature = packageMetaData . getEReference ( "IfcAxis2Placement3D" , "RefDirection" ) ; AbstractHashMapVirtualObject location = ifcAxis2Placement3D . getDirectFeature ( packageMetaData . getEReference ( "IfcPlacement" , "Location" ) ) ; if ( ifcAxis2Placement3D . getDirectFeature ( packageMetaData . getEReference ( "IfcAxis2Placement3D" , "Axis" ) ) != null && ifcAxis2Placement3D . getDirectFeature ( refDirectionFeature ) != null ) { AbstractHashMapVirtualObject axis = ifcAxis2Placement3D . getDirectFeature ( packageMetaData . getEReference ( "IfcAxis2Placement3D" , "Axis" ) ) ; AbstractHashMapVirtualObject direction = ifcAxis2Placement3D . getDirectFeature ( refDirectionFeature ) ; List < Double > axisDirectionRatios = ( List < Double > ) axis . get ( "DirectionRatios" ) ; List < Double > directionDirectionRatios = ( List < Double > ) direction . get ( "DirectionRatios" ) ; List < Double > locationCoordinates = ( List < Double > ) location . get ( "Coordinates" ) ; double [ ] cross = Vector . crossProduct ( new double [ ] { axisDirectionRatios . get ( 0 ) , axisDirectionRatios . get ( 1 ) , axisDirectionRatios . get ( 2 ) , 1 } , new double [ ] { directionDirectionRatios . get ( 0 ) , directionDirectionRatios . get ( 1 ) , directionDirectionRatios . get ( 2 ) , 1 } ) ; return new double [ ] { directionDirectionRatios . get ( 0 ) , directionDirectionRatios . get ( 1 ) , directionDirectionRatios . get ( 2 ) , 0 , cross [ 0 ] , cross [ 1 ] , cross [ 2 ] , 0 , axisDirectionRatios . get ( 0 ) , axisDirectionRatios . get ( 1 ) , axisDirectionRatios . get ( 2 ) , 0 , locationCoordinates . get ( 0 ) , locationCoordinates . get ( 1 ) , locationCoordinates . get ( 2 ) , 1 } ; } else if ( location != null ) { List < Double > locationCoordinates = ( List < Double > ) location . get ( "Coordinates" ) ; return new double [ ] { 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , locationCoordinates . get ( 0 ) , locationCoordinates . get ( 1 ) , locationCoordinates . get ( 2 ) , 1 } ; } return Matrix . identity ( ) ; } | Pretty sure this is working correctly |
11,342 | public static float length ( float [ ] u ) { return ( float ) Math . abs ( Math . sqrt ( ( u [ X ] * u [ X ] ) + ( u [ Y ] * u [ Y ] ) + ( u [ Z ] * u [ Z ] ) ) ) ; } | mangnatude or length |
11,343 | private static double getPlaneAngle ( float [ ] v1 , float [ ] v2 , float [ ] v3 , float [ ] u1 , float [ ] u2 , float [ ] u3 ) { float [ ] cross1 = Vector . crossProduct ( new float [ ] { v2 [ 0 ] - v1 [ 0 ] , v2 [ 1 ] - v1 [ 1 ] , v2 [ 2 ] - v1 [ 2 ] } , new float [ ] { v3 [ 0 ] - v1 [ 0 ] , v3 [ 1 ] - v1 [ 1 ] , v3 [ 2 ] - v1 [ 2 ] } ) ; float [ ] cross2 = Vector . crossProduct ( new float [ ] { u2 [ 0 ] - u1 [ 0 ] , u2 [ 1 ] - u1 [ 1 ] , u2 [ 2 ] - u1 [ 2 ] } , new float [ ] { u3 [ 0 ] - u1 [ 0 ] , u3 [ 1 ] - u1 [ 1 ] , u3 [ 2 ] - u1 [ 2 ] } ) ; float num = Vector . dot ( cross1 , cross2 ) ; float den = Vector . length ( cross1 ) * Vector . length ( cross2 ) ; float a = num / den ; if ( a > 1 ) { a = 1 ; } if ( a < - 1 ) { a = - 1 ; } double result = Math . acos ( a ) ; return result ; } | Get the angle in radians between two planes |
11,344 | public void addDecomposes ( IfcObjectDefinition parent , IfcObjectDefinition ... children ) throws IfcModelInterfaceException { IfcRelAggregates ifcRelAggregates = this . create ( IfcRelAggregates . class ) ; ifcRelAggregates . setRelatingObject ( parent ) ; for ( IfcObjectDefinition child : children ) { ifcRelAggregates . getRelatedObjects ( ) . add ( child ) ; } } | Create a decomposes relationship |
11,345 | public SMethod findMethod ( String methodName ) { for ( SService sService : servicesByName . values ( ) ) { SMethod method = sService . getSMethod ( methodName ) ; if ( method != null ) { return method ; } } return null ; } | Inefficient method of getting a SMethod |
11,346 | public void addField ( String fieldName ) throws QueryException { EReference feature = null ; for ( TypeDef typeDef : types ) { if ( typeDef . geteClass ( ) . getEStructuralFeature ( fieldName ) == null ) { throw new QueryException ( "Class \"" + typeDef . geteClass ( ) . getName ( ) + "\" does not have the field \"" + fieldName + "\"" ) ; } if ( feature == null ) { if ( ! ( typeDef . geteClass ( ) . getEStructuralFeature ( fieldName ) instanceof EReference ) ) { throw new QueryException ( fieldName + " is not a reference" ) ; } feature = ( EReference ) typeDef . geteClass ( ) . getEStructuralFeature ( fieldName ) ; } else { if ( feature != typeDef . geteClass ( ) . getEStructuralFeature ( fieldName ) ) { throw new QueryException ( "Classes \"" + typeDef . geteClass ( ) . getName ( ) + "\" and \"" + feature . getEContainingClass ( ) . getName ( ) + "\" have fields with the same name, but they are not logically the same" ) ; } } } if ( fields == null ) { fields = new ArrayList < > ( ) ; } fields . add ( feature ) ; } | Add the fields _after_ adding the types because the fields will be checked against the types all types should have the given field . |
11,347 | public static String getNewIfcGloballyUniqueId ( ) { Guid guid = getGuidFromUncompressedString ( UUID . randomUUID ( ) . toString ( ) ) ; String shortString = getCompressedStringFromGuid ( guid ) ; return shortString ; } | Generates a new GUID and returns a compressed string representation as used for IfcGloballyUniqueId |
11,348 | public static Guid getGuidFromUncompressedString ( String uncompressedGuidString ) { String [ ] parts = uncompressedGuidString . split ( "-" ) ; Guid guid = new Guid ( ) ; guid . Data1 = Long . parseLong ( parts [ 0 ] , 16 ) ; guid . Data2 = Integer . parseInt ( parts [ 1 ] , 16 ) ; guid . Data3 = Integer . parseInt ( parts [ 2 ] , 16 ) ; String temp ; temp = parts [ 3 ] ; guid . Data4 [ 0 ] = ( char ) Integer . parseInt ( temp . substring ( 0 , 2 ) , 16 ) ; guid . Data4 [ 1 ] = ( char ) Integer . parseInt ( temp . substring ( 2 , 4 ) , 16 ) ; temp = parts [ 4 ] ; guid . Data4 [ 2 ] = ( char ) Integer . parseInt ( temp . substring ( 0 , 2 ) , 16 ) ; guid . Data4 [ 3 ] = ( char ) Integer . parseInt ( temp . substring ( 2 , 4 ) , 16 ) ; guid . Data4 [ 4 ] = ( char ) Integer . parseInt ( temp . substring ( 4 , 6 ) , 16 ) ; guid . Data4 [ 5 ] = ( char ) Integer . parseInt ( temp . substring ( 6 , 8 ) , 16 ) ; guid . Data4 [ 6 ] = ( char ) Integer . parseInt ( temp . substring ( 8 , 10 ) , 16 ) ; guid . Data4 [ 7 ] = ( char ) Integer . parseInt ( temp . substring ( 10 , 12 ) , 16 ) ; return guid ; } | Converts an uncompressed String representation in an Guid - object |
11,349 | public static String getCompressedStringFromGuid ( Guid guid ) { long [ ] num = new long [ 6 ] ; char [ ] [ ] str = new char [ 6 ] [ 5 ] ; int i , j , n ; String result = new String ( ) ; num [ 0 ] = ( long ) ( guid . Data1 / 16777216 ) ; num [ 1 ] = ( long ) ( guid . Data1 % 16777216 ) ; num [ 2 ] = ( long ) ( guid . Data2 * 256 + guid . Data3 / 256 ) ; num [ 3 ] = ( long ) ( ( guid . Data3 % 256 ) * 65536 + guid . Data4 [ 0 ] * 256 + guid . Data4 [ 1 ] ) ; num [ 4 ] = ( long ) ( guid . Data4 [ 2 ] * 65536 + guid . Data4 [ 3 ] * 256 + guid . Data4 [ 4 ] ) ; num [ 5 ] = ( long ) ( guid . Data4 [ 5 ] * 65536 + guid . Data4 [ 6 ] * 256 + guid . Data4 [ 7 ] ) ; n = 3 ; for ( i = 0 ; i < 6 ; i ++ ) { if ( ! cv_to_64 ( num [ i ] , str [ i ] , n ) ) { return null ; } for ( j = 0 ; j < str [ i ] . length ; j ++ ) if ( str [ i ] [ j ] != '\0' ) result += str [ i ] [ j ] ; n = 5 ; } return result ; } | Converts a Guid - object into a compressed string representation of a GUID |
11,350 | private static boolean cv_to_64 ( long number , char [ ] code , int len ) { long act ; int iDigit , nDigits ; char [ ] result = new char [ 5 ] ; if ( len > 5 ) return false ; act = number ; nDigits = len - 1 ; for ( iDigit = 0 ; iDigit < nDigits ; iDigit ++ ) { result [ nDigits - iDigit - 1 ] = cConversionTable [ ( int ) ( act % 64 ) ] ; act /= 64 ; } result [ len - 1 ] = '\0' ; if ( act != 0 ) return false ; for ( int i = 0 ; i < result . length ; i ++ ) code [ i ] = result [ i ] ; return true ; } | Conversion of an integer into a number with base 64 using the table cConversionTable |
11,351 | private static boolean cv_from_64 ( long [ ] res , char [ ] str ) { int len , i , j , index ; for ( len = 1 ; len < 5 ; len ++ ) if ( str [ len ] == '\0' ) break ; res [ 0 ] = 0 ; for ( i = 0 ; i < len ; i ++ ) { index = - 1 ; for ( j = 0 ; j < 64 ; j ++ ) { if ( cConversionTable [ j ] == str [ i ] ) { index = j ; break ; } } if ( index == - 1 ) return false ; res [ 0 ] = res [ 0 ] * 64 + index ; } return true ; } | Calculate a numberer from the code |
11,352 | public static boolean getGuidFromCompressedString ( String string , Guid guid ) throws InvalidGuidException { char [ ] [ ] str = new char [ 6 ] [ 5 ] ; int len , i , j , m ; long [ ] [ ] num = new long [ 6 ] [ 1 ] ; len = string . length ( ) ; if ( len != 22 ) throw new InvalidGuidException ( string , "Length must be 22 (is: " + string . length ( ) + ")" ) ; j = 0 ; m = 2 ; for ( i = 0 ; i < 6 ; i ++ ) { for ( int k = 0 ; k < m ; k ++ ) { str [ i ] [ k ] = string . charAt ( j + k ) ; } str [ i ] [ m ] = '\0' ; j = j + m ; m = 4 ; } for ( i = 0 ; i < 6 ; i ++ ) { if ( ! cv_from_64 ( num [ i ] , str [ i ] ) ) { throw new InvalidGuidException ( string ) ; } } guid . Data1 = ( long ) ( num [ 0 ] [ 0 ] * 16777216 + num [ 1 ] [ 0 ] ) ; guid . Data2 = ( int ) ( num [ 2 ] [ 0 ] / 256 ) ; guid . Data3 = ( int ) ( ( num [ 2 ] [ 0 ] % 256 ) * 256 + num [ 3 ] [ 0 ] / 65536 ) ; guid . Data4 [ 0 ] = ( char ) ( ( num [ 3 ] [ 0 ] / 256 ) % 256 ) ; guid . Data4 [ 1 ] = ( char ) ( num [ 3 ] [ 0 ] % 256 ) ; guid . Data4 [ 2 ] = ( char ) ( num [ 4 ] [ 0 ] / 65536 ) ; guid . Data4 [ 3 ] = ( char ) ( ( num [ 4 ] [ 0 ] / 256 ) % 256 ) ; guid . Data4 [ 4 ] = ( char ) ( num [ 4 ] [ 0 ] % 256 ) ; guid . Data4 [ 5 ] = ( char ) ( num [ 5 ] [ 0 ] / 65536 ) ; guid . Data4 [ 6 ] = ( char ) ( ( num [ 5 ] [ 0 ] / 256 ) % 256 ) ; guid . Data4 [ 7 ] = ( char ) ( num [ 5 ] [ 0 ] % 256 ) ; return true ; } | Reconstructs a Guid - object form an compressed String representation of a GUID |
11,353 | public static String getUncompressedStringFromGuid ( Guid guid ) { String result = new String ( ) ; result += String . format ( "%1$08x" , guid . Data1 ) ; result += "-" ; result += String . format ( "%1$04x" , guid . Data2 ) ; result += "-" ; result += String . format ( "%1$04x" , guid . Data3 ) ; result += "-" ; result += String . format ( "%1$02x%2$02x" , ( int ) guid . Data4 [ 0 ] , ( int ) guid . Data4 [ 1 ] ) ; result += "-" ; result += String . format ( "%1$02x%2$02x%3$02x%4$02x%5$02x%6$02x" , ( int ) guid . Data4 [ 2 ] , ( int ) guid . Data4 [ 3 ] , ( int ) guid . Data4 [ 4 ] , ( int ) guid . Data4 [ 5 ] , ( int ) guid . Data4 [ 6 ] , ( int ) guid . Data4 [ 7 ] ) ; return result ; } | Converts a Guid - object into a uncompressed String representation of a GUID |
11,354 | public static String compressGuidString ( String uncompressedString ) { Guid guid = getGuidFromUncompressedString ( uncompressedString ) ; return getCompressedStringFromGuid ( guid ) ; } | Converts an uncompressed String representation of a GUID into a compressed one |
11,355 | public static String uncompressGuidString ( String compressedString ) throws InvalidGuidException { Guid guid = new Guid ( ) ; getGuidFromCompressedString ( compressedString , guid ) ; return getUncompressedStringFromGuid ( guid ) ; } | Converts a compressed String representation of a GUID into an uncompressed one |
11,356 | public void initAllLoadedPlugins ( ) throws PluginException { LOGGER . debug ( "Initializig all loaded plugins" ) ; for ( Class < ? extends Plugin > pluginClass : implementations . keySet ( ) ) { Set < PluginContext > set = implementations . get ( pluginClass ) ; for ( PluginContext pluginContext : set ) { try { pluginContext . initialize ( pluginContext . getSystemSettings ( ) ) ; } catch ( Throwable e ) { LOGGER . error ( "" , e ) ; pluginContext . setEnabled ( false , false ) ; } } } } | This method will initialize all the loaded plugins |
11,357 | public static Map < String , Object > listProperties ( IfcObject ifcObject , String propertySetName ) { Map < String , Object > result = new HashMap < > ( ) ; for ( IfcRelDefines ifcRelDefines : ifcObject . getIsDefinedBy ( ) ) { if ( ifcRelDefines instanceof IfcRelDefinesByProperties ) { IfcRelDefinesByProperties ifcRelDefinesByProperties = ( IfcRelDefinesByProperties ) ifcRelDefines ; IfcPropertySetDefinition propertySetDefinition = ifcRelDefinesByProperties . getRelatingPropertyDefinition ( ) ; if ( propertySetDefinition instanceof IfcPropertySet ) { IfcPropertySet ifcPropertySet = ( IfcPropertySet ) propertySetDefinition ; if ( ifcPropertySet . getName ( ) != null && ifcPropertySet . getName ( ) . equalsIgnoreCase ( propertySetName ) ) { for ( IfcProperty ifcProperty : ifcPropertySet . getHasProperties ( ) ) { if ( ifcProperty instanceof IfcPropertySingleValue ) { IfcPropertySingleValue propertyValue = ( IfcPropertySingleValue ) ifcProperty ; result . put ( propertyValue . getName ( ) , nominalValueToObject ( propertyValue . getNominalValue ( ) ) ) ; } } } } } } return result ; } | Lists all properties of a given IfcPopertySet that are of type IfcPropertySingleValue all values are converted to the appropriate Java type |
11,358 | public static void transposeM ( float [ ] mTrans , int mTransOffset , float [ ] m , int mOffset ) { for ( int i = 0 ; i < 4 ; i ++ ) { int mBase = i * 4 + mOffset ; mTrans [ i + mTransOffset ] = m [ mBase ] ; mTrans [ i + 4 + mTransOffset ] = m [ mBase + 1 ] ; mTrans [ i + 8 + mTransOffset ] = m [ mBase + 2 ] ; mTrans [ i + 12 + mTransOffset ] = m [ mBase + 3 ] ; } } | Transposes a 4 x 4 matrix . |
11,359 | public static void orthoM ( float [ ] m , int mOffset , float left , float right , float bottom , float top , float near , float far ) { if ( left == right ) { throw new IllegalArgumentException ( "left == right" ) ; } if ( bottom == top ) { throw new IllegalArgumentException ( "bottom == top" ) ; } if ( near == far ) { throw new IllegalArgumentException ( "near == far" ) ; } final float r_width = 1.0f / ( right - left ) ; final float r_height = 1.0f / ( top - bottom ) ; final float r_depth = 1.0f / ( far - near ) ; final float x = 2.0f * ( r_width ) ; final float y = 2.0f * ( r_height ) ; final float z = - 2.0f * ( r_depth ) ; final float tx = - ( right + left ) * r_width ; final float ty = - ( top + bottom ) * r_height ; final float tz = - ( far + near ) * r_depth ; m [ mOffset + 0 ] = x ; m [ mOffset + 5 ] = y ; m [ mOffset + 10 ] = z ; m [ mOffset + 12 ] = tx ; m [ mOffset + 13 ] = ty ; m [ mOffset + 14 ] = tz ; m [ mOffset + 15 ] = 1.0f ; m [ mOffset + 1 ] = 0.0f ; m [ mOffset + 2 ] = 0.0f ; m [ mOffset + 3 ] = 0.0f ; m [ mOffset + 4 ] = 0.0f ; m [ mOffset + 6 ] = 0.0f ; m [ mOffset + 7 ] = 0.0f ; m [ mOffset + 8 ] = 0.0f ; m [ mOffset + 9 ] = 0.0f ; m [ mOffset + 11 ] = 0.0f ; } | Computes an orthographic projection matrix . |
11,360 | public static void frustumM ( float [ ] m , int offset , float left , float right , float bottom , float top , float near , float far ) { if ( left == right ) { throw new IllegalArgumentException ( "left == right" ) ; } if ( top == bottom ) { throw new IllegalArgumentException ( "top == bottom" ) ; } if ( near == far ) { throw new IllegalArgumentException ( "near == far" ) ; } if ( near <= 0.0f ) { throw new IllegalArgumentException ( "near <= 0.0f" ) ; } if ( far <= 0.0f ) { throw new IllegalArgumentException ( "far <= 0.0f" ) ; } final float r_width = 1.0f / ( right - left ) ; final float r_height = 1.0f / ( top - bottom ) ; final float r_depth = 1.0f / ( near - far ) ; final float x = 2.0f * ( near * r_width ) ; final float y = 2.0f * ( near * r_height ) ; final float A = ( right + left ) * r_width ; final float B = ( top + bottom ) * r_height ; final float C = ( far + near ) * r_depth ; final float D = 2.0f * ( far * near * r_depth ) ; m [ offset + 0 ] = x ; m [ offset + 5 ] = y ; m [ offset + 8 ] = A ; m [ offset + 9 ] = B ; m [ offset + 10 ] = C ; m [ offset + 14 ] = D ; m [ offset + 11 ] = - 1.0f ; m [ offset + 1 ] = 0.0f ; m [ offset + 2 ] = 0.0f ; m [ offset + 3 ] = 0.0f ; m [ offset + 4 ] = 0.0f ; m [ offset + 6 ] = 0.0f ; m [ offset + 7 ] = 0.0f ; m [ offset + 12 ] = 0.0f ; m [ offset + 13 ] = 0.0f ; m [ offset + 15 ] = 0.0f ; } | Define a projection matrix in terms of six clip planes |
11,361 | public static void perspectiveM ( float [ ] m , int offset , float fovy , float aspect , float zNear , float zFar ) { float f = 1.0f / ( float ) Math . tan ( fovy * ( Math . PI / 360.0 ) ) ; float rangeReciprocal = 1.0f / ( zNear - zFar ) ; m [ offset + 0 ] = f / aspect ; m [ offset + 1 ] = 0.0f ; m [ offset + 2 ] = 0.0f ; m [ offset + 3 ] = 0.0f ; m [ offset + 4 ] = 0.0f ; m [ offset + 5 ] = f ; m [ offset + 6 ] = 0.0f ; m [ offset + 7 ] = 0.0f ; m [ offset + 8 ] = 0.0f ; m [ offset + 9 ] = 0.0f ; m [ offset + 10 ] = ( zFar + zNear ) * rangeReciprocal ; m [ offset + 11 ] = - 1.0f ; m [ offset + 12 ] = 0.0f ; m [ offset + 13 ] = 0.0f ; m [ offset + 14 ] = 2.0f * zFar * zNear * rangeReciprocal ; m [ offset + 15 ] = 0.0f ; } | Define a projection matrix in terms of a field of view angle an aspect ratio and z clip planes |
11,362 | public static void setIdentityM ( float [ ] sm , int smOffset ) { for ( int i = 0 ; i < 16 ; i ++ ) { sm [ smOffset + i ] = 0 ; } for ( int i = 0 ; i < 16 ; i += 5 ) { sm [ smOffset + i ] = 1.0f ; } } | Sets matrix m to the identity matrix . |
11,363 | public static void scaleM ( float [ ] sm , int smOffset , float [ ] m , int mOffset , float x , float y , float z ) { for ( int i = 0 ; i < 4 ; i ++ ) { int smi = smOffset + i ; int mi = mOffset + i ; sm [ smi ] = m [ mi ] * x ; sm [ 4 + smi ] = m [ 4 + mi ] * y ; sm [ 8 + smi ] = m [ 8 + mi ] * z ; sm [ 12 + smi ] = m [ 12 + mi ] ; } } | Scales matrix m by x y and z putting the result in sm |
11,364 | public static void translateM ( float [ ] tm , int tmOffset , float [ ] m , int mOffset , float x , float y , float z ) { for ( int i = 0 ; i < 12 ; i ++ ) { tm [ tmOffset + i ] = m [ mOffset + i ] ; } for ( int i = 0 ; i < 4 ; i ++ ) { int tmi = tmOffset + i ; int mi = mOffset + i ; tm [ 12 + tmi ] = m [ mi ] * x + m [ 4 + mi ] * y + m [ 8 + mi ] * z + m [ 12 + mi ] ; } } | Translates matrix m by x y and z putting the result in tm |
11,365 | public static void translateM ( float [ ] m , int mOffset , float x , float y , float z ) { for ( int i = 0 ; i < 4 ; i ++ ) { int mi = mOffset + i ; m [ 12 + mi ] += m [ mi ] * x + m [ 4 + mi ] * y + m [ 8 + mi ] * z ; } } | Translates matrix m by x y and z in place . |
11,366 | public static void setRotateEulerM ( float [ ] rm , int rmOffset , float x , float y , float z ) { x *= ( float ) ( Math . PI / 180.0f ) ; y *= ( float ) ( Math . PI / 180.0f ) ; z *= ( float ) ( Math . PI / 180.0f ) ; float cx = ( float ) Math . cos ( x ) ; float sx = ( float ) Math . sin ( x ) ; float cy = ( float ) Math . cos ( y ) ; float sy = ( float ) Math . sin ( y ) ; float cz = ( float ) Math . cos ( z ) ; float sz = ( float ) Math . sin ( z ) ; float cxsy = cx * sy ; float sxsy = sx * sy ; rm [ rmOffset + 0 ] = cy * cz ; rm [ rmOffset + 1 ] = - cy * sz ; rm [ rmOffset + 2 ] = sy ; rm [ rmOffset + 3 ] = 0.0f ; rm [ rmOffset + 4 ] = cxsy * cz + cx * sz ; rm [ rmOffset + 5 ] = - cxsy * sz + cx * cz ; rm [ rmOffset + 6 ] = - sx * cy ; rm [ rmOffset + 7 ] = 0.0f ; rm [ rmOffset + 8 ] = - sxsy * cz + sx * sz ; rm [ rmOffset + 9 ] = sxsy * sz + sx * cz ; rm [ rmOffset + 10 ] = cx * cy ; rm [ rmOffset + 11 ] = 0.0f ; rm [ rmOffset + 12 ] = 0.0f ; rm [ rmOffset + 13 ] = 0.0f ; rm [ rmOffset + 14 ] = 0.0f ; rm [ rmOffset + 15 ] = 1.0f ; } | Converts Euler angles to a rotation matrix |
11,367 | public static void setLookAtM ( float [ ] rm , int rmOffset , float eyeX , float eyeY , float eyeZ , float centerX , float centerY , float centerZ , float upX , float upY , float upZ ) { float fx = centerX - eyeX ; float fy = centerY - eyeY ; float fz = centerZ - eyeZ ; float rlf = 1.0f / Matrix . length ( fx , fy , fz ) ; fx *= rlf ; fy *= rlf ; fz *= rlf ; float sx = fy * upZ - fz * upY ; float sy = fz * upX - fx * upZ ; float sz = fx * upY - fy * upX ; float rls = 1.0f / Matrix . length ( sx , sy , sz ) ; sx *= rls ; sy *= rls ; sz *= rls ; float ux = sy * fz - sz * fy ; float uy = sz * fx - sx * fz ; float uz = sx * fy - sy * fx ; rm [ rmOffset + 0 ] = sx ; rm [ rmOffset + 1 ] = ux ; rm [ rmOffset + 2 ] = - fx ; rm [ rmOffset + 3 ] = 0.0f ; rm [ rmOffset + 4 ] = sy ; rm [ rmOffset + 5 ] = uy ; rm [ rmOffset + 6 ] = - fy ; rm [ rmOffset + 7 ] = 0.0f ; rm [ rmOffset + 8 ] = sz ; rm [ rmOffset + 9 ] = uz ; rm [ rmOffset + 10 ] = - fz ; rm [ rmOffset + 11 ] = 0.0f ; rm [ rmOffset + 12 ] = 0.0f ; rm [ rmOffset + 13 ] = 0.0f ; rm [ rmOffset + 14 ] = 0.0f ; rm [ rmOffset + 15 ] = 1.0f ; translateM ( rm , rmOffset , - eyeX , - eyeY , - eyeZ ) ; } | Define a viewing transformation in terms of an eye point a center of view and an up vector . |
11,368 | public void activateServices ( ) throws BimserverDatabaseException , BimserverLockConflictException { try ( DatabaseSession session = bimDatabase . createSession ( ) ) { IfcModelInterface allOfType = session . getAllOfType ( StorePackage . eINSTANCE . getUser ( ) , OldQuery . getDefault ( ) ) ; for ( User user : allOfType . getAll ( User . class ) ) { updateUserSettings ( session , user ) ; UserSettings userSettings = user . getUserSettings ( ) ; for ( InternalServicePluginConfiguration internalServicePluginConfiguration : userSettings . getServices ( ) ) { activateService ( user . getOid ( ) , internalServicePluginConfiguration ) ; } } } } | Load all users from the database and their configured services . Registers each service . |
11,369 | public static void printSizes ( Component c ) { System . out . println ( "minimumSize = " + c . getMinimumSize ( ) ) ; System . out . println ( "preferredSize = " + c . getPreferredSize ( ) ) ; System . out . println ( "maximumSize = " + c . getMaximumSize ( ) ) ; } | A debugging utility that prints to stdout the component s minimum preferred and maximum sizes . |
11,370 | public String toGav ( ) { if ( purl . getNamespace ( ) != null && purl . getVersion ( ) != null ) { return String . format ( "%s:%s:%s" , purl . getNamespace ( ) , purl . getName ( ) , purl . getVersion ( ) ) ; } return null ; } | Returns the GAV representation of the Package URL as utilized in gradle builds . |
11,371 | public static SAXParser buildSecureSaxParser ( InputStream ... schemaStream ) throws ParserConfigurationException , SAXNotRecognizedException , SAXNotSupportedException , SAXException { final SAXParserFactory factory = SAXParserFactory . newInstance ( ) ; factory . setNamespaceAware ( true ) ; factory . setValidating ( true ) ; factory . setFeature ( "http://apache.org/xml/features/disallow-doctype-decl" , true ) ; factory . setFeature ( "http://xml.org/sax/features/external-general-entities" , false ) ; final SAXParser saxParser = factory . newSAXParser ( ) ; saxParser . setProperty ( JAXP_SCHEMA_LANGUAGE , W3C_XML_SCHEMA ) ; saxParser . setProperty ( JAXP_SCHEMA_SOURCE , schemaStream ) ; return saxParser ; } | Constructs a validating secure SAX Parser . |
11,372 | public static SAXParser buildSecureSaxParser ( ) throws ParserConfigurationException , SAXNotRecognizedException , SAXNotSupportedException , SAXException { final SAXParserFactory factory = SAXParserFactory . newInstance ( ) ; factory . setFeature ( "http://apache.org/xml/features/disallow-doctype-decl" , true ) ; factory . setFeature ( "http://xml.org/sax/features/external-general-entities" , false ) ; factory . setFeature ( XMLConstants . FEATURE_SECURE_PROCESSING , true ) ; return factory . newSAXParser ( ) ; } | Constructs a secure SAX Parser . |
11,373 | public static DocumentBuilder buildSecureDocumentBuilder ( ) throws ParserConfigurationException { final DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; factory . setFeature ( "http://apache.org/xml/features/disallow-doctype-decl" , true ) ; factory . setFeature ( "http://xml.org/sax/features/external-general-entities" , false ) ; factory . setFeature ( XMLConstants . FEATURE_SECURE_PROCESSING , true ) ; return factory . newDocumentBuilder ( ) ; } | Constructs a new document builder with security features enabled . |
11,374 | public static String getPrettyParseExceptionInfo ( SAXParseException ex ) { final StringBuilder sb = new StringBuilder ( ) ; if ( ex . getSystemId ( ) != null ) { sb . append ( "systemId=" ) . append ( ex . getSystemId ( ) ) . append ( ", " ) ; } if ( ex . getPublicId ( ) != null ) { sb . append ( "publicId=" ) . append ( ex . getPublicId ( ) ) . append ( ", " ) ; } if ( ex . getLineNumber ( ) > 0 ) { sb . append ( "Line=" ) . append ( ex . getLineNumber ( ) ) ; } if ( ex . getColumnNumber ( ) > 0 ) { sb . append ( ", Column=" ) . append ( ex . getColumnNumber ( ) ) ; } sb . append ( ": " ) . append ( ex . getMessage ( ) ) ; return sb . toString ( ) ; } | Builds a prettier exception message . |
11,375 | public synchronized void save ( NvdCveInfo updatedValue ) throws UpdateException { if ( updatedValue == null ) { return ; } save ( LAST_UPDATED_BASE + updatedValue . getId ( ) , String . valueOf ( updatedValue . getTimestamp ( ) ) ) ; } | Saves the last updated information to the properties file . |
11,376 | public synchronized void save ( String key , String value ) throws UpdateException { properties . put ( key , value ) ; cveDB . saveProperty ( key , value ) ; } | Saves the key value pair to the properties store . |
11,377 | public synchronized Map < String , String > getMetaData ( ) { final Map < String , String > map = new TreeMap < > ( ) ; for ( Entry < Object , Object > entry : properties . entrySet ( ) ) { final String key = ( String ) entry . getKey ( ) ; if ( ! "version" . equals ( key ) ) { if ( key . startsWith ( "NVD CVE " ) ) { try { final long epoch = Long . parseLong ( ( String ) entry . getValue ( ) ) ; final DateTime date = new DateTime ( epoch ) ; final DateTimeFormatter format = DateTimeFormat . forPattern ( "dd/MM/yyyy HH:mm:ss" ) ; final String formatted = format . print ( date ) ; map . put ( key , formatted ) ; } catch ( Throwable ex ) { LOGGER . debug ( "Unable to parse timestamp from DB" , ex ) ; map . put ( key , ( String ) entry . getValue ( ) ) ; } } else { map . put ( key , ( String ) entry . getValue ( ) ) ; } } } return map ; } | Returns a map of the meta data from the database properties . This primarily contains timestamps of when the NVD CVE information was last updated . |
11,378 | public void processProperties ( Properties properties ) { this . groupId = interpolateString ( this . groupId , properties ) ; this . artifactId = interpolateString ( this . artifactId , properties ) ; this . version = interpolateString ( this . version , properties ) ; this . description = interpolateString ( this . description , properties ) ; for ( License l : this . getLicenses ( ) ) { l . setName ( interpolateString ( l . getName ( ) , properties ) ) ; l . setUrl ( interpolateString ( l . getUrl ( ) , properties ) ) ; } this . name = interpolateString ( this . name , properties ) ; this . projectURL = interpolateString ( this . projectURL , properties ) ; this . organization = interpolateString ( this . organization , properties ) ; this . parentGroupId = interpolateString ( this . parentGroupId , properties ) ; this . parentArtifactId = interpolateString ( this . parentArtifactId , properties ) ; this . parentVersion = interpolateString ( this . parentVersion , properties ) ; } | Process the Maven properties file and interpolate all properties . |
11,379 | public void execute ( ) throws BuildException { populateSettings ( ) ; try ( Engine engine = new Engine ( Update . class . getClassLoader ( ) , getSettings ( ) ) ) { try { engine . doUpdates ( ) ; } catch ( UpdateException ex ) { if ( this . isFailOnError ( ) ) { throw new BuildException ( ex ) ; } log ( ex . getMessage ( ) , Project . MSG_ERR ) ; } } catch ( DatabaseException ex ) { final String msg = "Unable to connect to the dependency-check database; unable to update the NVD data" ; if ( this . isFailOnError ( ) ) { throw new BuildException ( msg , ex ) ; } log ( msg , Project . MSG_ERR ) ; } finally { getSettings ( ) . cleanup ( ) ; } } | Executes the update by initializing the settings downloads the NVD XML data and then processes the data storing it in the local database . |
11,380 | public boolean update ( Engine engine ) throws UpdateException { this . settings = engine . getSettings ( ) ; try { final CveDB db = engine . getDatabase ( ) ; final boolean autoupdate = settings . getBoolean ( Settings . KEYS . AUTO_UPDATE , true ) ; final boolean enabled = settings . getBoolean ( Settings . KEYS . UPDATE_VERSION_CHECK_ENABLED , true ) ; final String original = settings . getString ( Settings . KEYS . CVE_ORIGINAL_JSON ) ; final String current = settings . getString ( Settings . KEYS . CVE_MODIFIED_JSON ) ; if ( enabled && autoupdate && original != null && original . equals ( current ) ) { LOGGER . debug ( "Begin Engine Version Check" ) ; final DatabaseProperties properties = db . getDatabaseProperties ( ) ; final long lastChecked = Long . parseLong ( properties . getProperty ( ENGINE_VERSION_CHECKED_ON , "0" ) ) ; final long now = System . currentTimeMillis ( ) ; updateToVersion = properties . getProperty ( CURRENT_ENGINE_RELEASE , "" ) ; final String currentVersion = settings . getString ( Settings . KEYS . APPLICATION_VERSION , "0.0.0" ) ; LOGGER . debug ( "Last checked: {}" , lastChecked ) ; LOGGER . debug ( "Now: {}" , now ) ; LOGGER . debug ( "Current version: {}" , currentVersion ) ; final boolean updateNeeded = shouldUpdate ( lastChecked , now , properties , currentVersion ) ; if ( updateNeeded ) { LOGGER . warn ( "A new version of dependency-check is available. Consider updating to version {}." , updateToVersion ) ; } } } catch ( DatabaseException ex ) { LOGGER . debug ( "Database Exception opening databases to retrieve properties" , ex ) ; throw new UpdateException ( "Error occurred updating database properties." ) ; } catch ( InvalidSettingException ex ) { LOGGER . debug ( "Unable to determine if autoupdate is enabled" , ex ) ; } return false ; } | Downloads the current released version number and compares it to the running engine s version number . If the released version number is newer a warning is printed recommending an upgrade . |
11,381 | protected boolean shouldUpdate ( final long lastChecked , final long now , final DatabaseProperties properties , String currentVersion ) throws UpdateException { final int checkRange = 30 ; if ( ! DateUtil . withinDateRange ( lastChecked , now , checkRange ) ) { LOGGER . debug ( "Checking web for new version." ) ; final String currentRelease = getCurrentReleaseVersion ( ) ; if ( currentRelease != null ) { final DependencyVersion v = new DependencyVersion ( currentRelease ) ; if ( v . getVersionParts ( ) != null && v . getVersionParts ( ) . size ( ) >= 3 ) { updateToVersion = v . toString ( ) ; if ( ! currentRelease . equals ( updateToVersion ) ) { properties . save ( CURRENT_ENGINE_RELEASE , updateToVersion ) ; } properties . save ( ENGINE_VERSION_CHECKED_ON , Long . toString ( now ) ) ; } } LOGGER . debug ( "Current Release: {}" , updateToVersion ) ; } if ( updateToVersion == null ) { LOGGER . debug ( "Unable to obtain current release" ) ; return false ; } final DependencyVersion running = new DependencyVersion ( currentVersion ) ; final DependencyVersion released = new DependencyVersion ( updateToVersion ) ; if ( running . compareTo ( released ) < 0 ) { LOGGER . debug ( "Upgrade recommended" ) ; return true ; } LOGGER . debug ( "Upgrade not needed" ) ; return false ; } | Determines if a new version of the dependency - check engine has been released . |
11,382 | protected String getCurrentReleaseVersion ( ) { HttpURLConnection conn = null ; try { final String str = settings . getString ( Settings . KEYS . ENGINE_VERSION_CHECK_URL , "http://jeremylong.github.io/DependencyCheck/current.txt" ) ; final URL url = new URL ( str ) ; final URLConnectionFactory factory = new URLConnectionFactory ( settings ) ; conn = factory . createHttpURLConnection ( url ) ; conn . connect ( ) ; if ( conn . getResponseCode ( ) != 200 ) { return null ; } final String releaseVersion = IOUtils . toString ( conn . getInputStream ( ) , StandardCharsets . UTF_8 ) ; if ( releaseVersion != null ) { return releaseVersion . trim ( ) ; } } catch ( MalformedURLException ex ) { LOGGER . debug ( "Unable to retrieve current release version of dependency-check - malformed url?" ) ; } catch ( URLConnectionFailureException ex ) { LOGGER . debug ( "Unable to retrieve current release version of dependency-check - connection failed" ) ; } catch ( IOException ex ) { LOGGER . debug ( "Unable to retrieve current release version of dependency-check - i/o exception" ) ; } finally { if ( conn != null ) { conn . disconnect ( ) ; } } return null ; } | Retrieves the current released version number from the github documentation site . |
11,383 | public static CharArraySet getStopWords ( ) { final CharArraySet words = StopFilter . makeStopSet ( ADDITIONAL_STOP_WORDS , true ) ; words . addAll ( EnglishAnalyzer . ENGLISH_STOP_WORDS_SET ) ; return words ; } | Returns the set of stop words being used . |
11,384 | protected TokenStreamComponents createComponents ( String fieldName ) { final Tokenizer source = new WhitespaceTokenizer ( ) ; TokenStream stream = source ; stream = new UrlTokenizingFilter ( stream ) ; stream = new AlphaNumericFilter ( stream ) ; stream = new WordDelimiterGraphFilter ( stream , WordDelimiterGraphFilter . GENERATE_WORD_PARTS | WordDelimiterGraphFilter . PRESERVE_ORIGINAL | WordDelimiterGraphFilter . SPLIT_ON_CASE_CHANGE | WordDelimiterGraphFilter . SPLIT_ON_NUMERICS | WordDelimiterGraphFilter . STEM_ENGLISH_POSSESSIVE , null ) ; stream = new LowerCaseFilter ( stream ) ; stream = new StopFilter ( stream , stopWords ) ; concatenatingFilter = new TokenPairConcatenatingFilter ( stream ) ; return new TokenStreamComponents ( source , concatenatingFilter ) ; } | Creates a the TokenStreamComponents used to analyze the stream . |
11,385 | private void initSSLSocketFactoryEx ( KeyManager [ ] km , TrustManager [ ] tm , SecureRandom random ) throws NoSuchAlgorithmException , KeyManagementException { sslCtxt = SSLContext . getInstance ( "TLS" ) ; sslCtxt . init ( km , tm , random ) ; protocols = getProtocolList ( ) ; } | Initializes the SSL Socket Factory Extension . |
11,386 | @ SuppressWarnings ( "StringSplitter" ) protected String [ ] getProtocolList ( ) { SSLSocket socket = null ; String [ ] availableProtocols = null ; final String [ ] preferredProtocols = settings . getString ( Settings . KEYS . DOWNLOADER_TLS_PROTOCOL_LIST , "TLSv1.1,TLSv1.2,TLSv1.3" ) . split ( "," ) ; try { final SSLSocketFactory factory = sslCtxt . getSocketFactory ( ) ; socket = ( SSLSocket ) factory . createSocket ( ) ; availableProtocols = socket . getSupportedProtocols ( ) ; Arrays . sort ( availableProtocols ) ; if ( LOGGER . isDebugEnabled ( ) && ! protocolsLogged ) { protocolsLogged = true ; LOGGER . debug ( "Available Protocols:" ) ; for ( String p : availableProtocols ) { LOGGER . debug ( p ) ; } } } catch ( Exception ex ) { LOGGER . debug ( "Error getting protocol list, using TLSv1.1-1.3" , ex ) ; return new String [ ] { "TLSv1.1" , "TLSv1.2" , "TLSv1.3" } ; } finally { if ( socket != null ) { try { socket . close ( ) ; } catch ( IOException ex ) { LOGGER . trace ( "Error closing socket" , ex ) ; } } } final List < String > aa = new ArrayList < > ( ) ; for ( String preferredProtocol : preferredProtocols ) { final int idx = Arrays . binarySearch ( availableProtocols , preferredProtocol ) ; if ( idx >= 0 ) { aa . add ( preferredProtocol ) ; } } return aa . toArray ( new String [ 0 ] ) ; } | Returns the protocol list . |
11,387 | public Iterable < T > filter ( final Iterable < T > iterable ) { return new Iterable < T > ( ) { public Iterator < T > iterator ( ) { return filter ( iterable . iterator ( ) ) ; } } ; } | Filters a given iterable . |
11,388 | private boolean cpeIdentifiersMatch ( Dependency dependency1 , Dependency dependency2 ) { if ( dependency1 == null || dependency1 . getVulnerableSoftwareIdentifiers ( ) == null || dependency2 == null || dependency2 . getVulnerableSoftwareIdentifiers ( ) == null ) { return false ; } boolean matches = false ; final int cpeCount1 = dependency1 . getVulnerableSoftwareIdentifiers ( ) . size ( ) ; final int cpeCount2 = dependency2 . getVulnerableSoftwareIdentifiers ( ) . size ( ) ; if ( cpeCount1 > 0 && cpeCount1 == cpeCount2 ) { for ( Identifier i : dependency1 . getVulnerableSoftwareIdentifiers ( ) ) { matches |= dependency2 . getVulnerableSoftwareIdentifiers ( ) . contains ( i ) ; if ( ! matches ) { break ; } } } LOGGER . debug ( "IdentifiersMatch={} ({}, {})" , matches , dependency1 . getFileName ( ) , dependency2 . getFileName ( ) ) ; return matches ; } | Returns true if the CPE identifiers in the two supplied dependencies are equal . |
11,389 | private boolean vulnerabilitiesMatch ( Dependency dependency1 , Dependency dependency2 ) { final Set < Vulnerability > one = dependency1 . getVulnerabilities ( ) ; final Set < Vulnerability > two = dependency2 . getVulnerabilities ( ) ; return one != null && two != null && one . size ( ) == two . size ( ) && one . containsAll ( two ) ; } | Returns true if the two dependencies have the same vulnerabilities . |
11,390 | private boolean hasSameBasePath ( Dependency dependency1 , Dependency dependency2 ) { if ( dependency1 == null || dependency2 == null ) { return false ; } final File lFile = new File ( dependency1 . getFilePath ( ) ) ; String left = lFile . getParent ( ) ; final File rFile = new File ( dependency2 . getFilePath ( ) ) ; String right = rFile . getParent ( ) ; if ( left == null ) { return right == null ; } else if ( right == null ) { return false ; } if ( left . equalsIgnoreCase ( right ) ) { return true ; } if ( left . matches ( ".*[/\\\\](repository|local-repo)[/\\\\].*" ) && right . matches ( ".*[/\\\\](repository|local-repo)[/\\\\].*" ) ) { left = getBaseRepoPath ( left ) ; right = getBaseRepoPath ( right ) ; } if ( left . equalsIgnoreCase ( right ) ) { return true ; } for ( Dependency child : dependency2 . getRelatedDependencies ( ) ) { if ( hasSameBasePath ( child , dependency1 ) ) { return true ; } } return false ; } | Determines if the two dependencies have the same base path . |
11,391 | protected boolean isCore ( Dependency left , Dependency right ) { final String leftName = left . getFileName ( ) . toLowerCase ( ) ; final String rightName = right . getFileName ( ) . toLowerCase ( ) ; final boolean returnVal ; if ( left . isVirtual ( ) && ! right . isVirtual ( ) ) { returnVal = true ; } else if ( ! left . isVirtual ( ) && right . isVirtual ( ) ) { returnVal = false ; } else if ( ( ! rightName . matches ( ".*\\.(tar|tgz|gz|zip|ear|war).+" ) && leftName . matches ( ".*\\.(tar|tgz|gz|zip|ear|war).+" ) ) || ( rightName . contains ( "core" ) && ! leftName . contains ( "core" ) ) || ( rightName . contains ( "kernel" ) && ! leftName . contains ( "kernel" ) ) || ( rightName . contains ( "akka-stream" ) && ! leftName . contains ( "akka-stream" ) ) || ( rightName . contains ( "netty-transport" ) && ! leftName . contains ( "netty-transport" ) ) ) { returnVal = false ; } else if ( ( rightName . matches ( ".*\\.(tar|tgz|gz|zip|ear|war).+" ) && ! leftName . matches ( ".*\\.(tar|tgz|gz|zip|ear|war).+" ) ) || ( ! rightName . contains ( "core" ) && leftName . contains ( "core" ) ) || ( ! rightName . contains ( "kernel" ) && leftName . contains ( "kernel" ) ) || ( ! rightName . contains ( "akka-stream" ) && leftName . contains ( "akka-stream" ) ) || ( ! rightName . contains ( "netty-transport" ) && leftName . contains ( "netty-transport" ) ) ) { returnVal = true ; } else { returnVal = leftName . length ( ) <= rightName . length ( ) ; } LOGGER . debug ( "IsCore={} ({}, {})" , returnVal , left . getFileName ( ) , right . getFileName ( ) ) ; return returnVal ; } | This is likely a very broken attempt at determining if the left dependency is the core library in comparison to the right library . |
11,392 | private boolean hashesMatch ( Dependency dependency1 , Dependency dependency2 ) { if ( dependency1 == null || dependency2 == null || dependency1 . getSha1sum ( ) == null || dependency2 . getSha1sum ( ) == null ) { return false ; } return dependency1 . getSha1sum ( ) . equals ( dependency2 . getSha1sum ( ) ) ; } | Compares the SHA1 hashes of two dependencies to determine if they are equal . |
11,393 | protected boolean isShadedJar ( Dependency dependency , Dependency nextDependency ) { if ( dependency == null || dependency . getFileName ( ) == null || nextDependency == null || nextDependency . getFileName ( ) == null || dependency . getSoftwareIdentifiers ( ) . isEmpty ( ) || nextDependency . getSoftwareIdentifiers ( ) . isEmpty ( ) ) { return false ; } final String mainName = dependency . getFileName ( ) . toLowerCase ( ) ; final String nextName = nextDependency . getFileName ( ) . toLowerCase ( ) ; if ( mainName . endsWith ( ".jar" ) && nextName . endsWith ( "pom.xml" ) ) { return dependency . getSoftwareIdentifiers ( ) . containsAll ( nextDependency . getSoftwareIdentifiers ( ) ) ; } else if ( nextName . endsWith ( ".jar" ) && mainName . endsWith ( "pom.xml" ) ) { return nextDependency . getSoftwareIdentifiers ( ) . containsAll ( dependency . getSoftwareIdentifiers ( ) ) ; } return false ; } | Determines if the jar is shaded and the created pom . xml identified the same CPE as the jar - if so the pom . xml dependency should be removed . |
11,394 | private int countChar ( String string , char c ) { int count = 0 ; final int max = string . length ( ) ; for ( int i = 0 ; i < max ; i ++ ) { if ( c == string . charAt ( i ) ) { count ++ ; } } return count ; } | Counts the number of times the character is present in the string . |
11,395 | private boolean ecoSystemIs ( String ecoSystem , Dependency dependency , Dependency nextDependency ) { return ecoSystem . equals ( dependency . getEcosystem ( ) ) && ecoSystem . equals ( nextDependency . getEcosystem ( ) ) ; } | Determine if the dependency ecosystem is equal in the given dependencies . |
11,396 | private boolean namesAreEqual ( Dependency dependency , Dependency nextDependency ) { return dependency . getName ( ) != null && dependency . getName ( ) . equals ( nextDependency . getName ( ) ) ; } | Determine if the dependency name is equal in the given dependencies . |
11,397 | public static boolean npmVersionsMatch ( String current , String next ) { String left = current ; String right = next ; if ( left == null || right == null ) { return false ; } if ( left . equals ( right ) || "*" . equals ( left ) || "*" . equals ( right ) ) { return true ; } if ( left . contains ( " " ) ) { if ( right . contains ( " " ) ) { return false ; } if ( ! right . matches ( "^\\d.*$" ) ) { right = stripLeadingNonNumeric ( right ) ; if ( right == null ) { return false ; } } try { final Semver v = new Semver ( right , SemverType . NPM ) ; return v . satisfies ( left ) ; } catch ( SemverException ex ) { LOGGER . trace ( "ignore" , ex ) ; } } else { if ( ! left . matches ( "^\\d.*$" ) ) { left = stripLeadingNonNumeric ( left ) ; if ( left == null || left . isEmpty ( ) ) { return false ; } } try { Semver v = new Semver ( left , SemverType . NPM ) ; if ( ! right . isEmpty ( ) && v . satisfies ( right ) ) { return true ; } if ( ! right . contains ( " " ) ) { left = current ; right = stripLeadingNonNumeric ( right ) ; if ( right != null ) { v = new Semver ( right , SemverType . NPM ) ; return v . satisfies ( left ) ; } } } catch ( SemverException ex ) { LOGGER . trace ( "ignore" , ex ) ; } catch ( NullPointerException ex ) { LOGGER . error ( "SemVer comparison error: left:\"{}\", right:\"{}\"" , left , right ) ; LOGGER . debug ( "SemVer comparison resulted in NPE" , ex ) ; } } return false ; } | Determine if the dependency version is equal in the given dependencies . This method attempts to evaluate version range checks . |
11,398 | private static String stripLeadingNonNumeric ( String str ) { for ( int x = 0 ; x < str . length ( ) ; x ++ ) { if ( Character . isDigit ( str . codePointAt ( x ) ) ) { return str . substring ( x ) ; } } return null ; } | Strips leading non - numeric values from the start of the string . If no numbers are present this will return null . |
11,399 | public List < Reference > getReferences ( boolean sorted ) { final List < Reference > sortedRefs = new ArrayList < > ( this . references ) ; if ( sorted ) { Collections . sort ( sortedRefs ) ; } return sortedRefs ; } | Returns the list of references . This is primarily used within the generated reports . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.