stevedlawrence commented on code in PR #919: URL: https://github.com/apache/daffodil/pull/919#discussion_r1092199637
########## project/OsgiCheck.scala: ########## @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import sbt._ +import sbt.Keys._ +import sbt.KeyRanks._ + +object OsgiCheckPlugin extends AutoPlugin { + + class OsgiCheckException() + extends RuntimeException("OSGI check failed") + with FeedbackProvidedException + + object autoImport { + val osgiOwnedPackages = taskKey[Set[String]]("Get all packages owned by this project").withRank(BTask) + val osgiOwnedPackagesWithOwner = taskKey[(Set[String], String)]("Get a tuple of the osgiOwnedPackages and the project name that owns them").withRank(Invisible) + val osgiCheck = taskKey[Unit]("Check all subpackages for osgi conflicts").withRank(ATask) + } + + import autoImport._ + + private val packageMatcher = """^\s*package (\S+);?.*$""".r + + override def trigger = allRequirements + + val allSubprojectsFilter = ScopeFilter(inAggregates(ThisProject, includeRoot=false)) + + override def projectSettings: Seq[Def.Setting[_]] = {Seq( + osgiOwnedPackages := { + (Compile / sources).value.flatMap { file => + var source = scala.io.Source.fromFile(file) + val optPackage = source.getLines.collectFirst { + case packageMatcher(packageName) => packageName + } + optPackage Review Comment: The previous approach ignored with a warning, This just silently ignores, which feels wrong. Seems we either want to warn if optPackage is empty as before, or throw an exception if optPackage isn't defined and require they be fixed. We coukd also change the packageMatcher to allow commented out package lines which I think is the one case where optPackage is empty right now. I have no strong preference either way. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
