首页 \ 问答 \ 如何在Java模块中指定源和目标兼容性?(How to specify source and target compatibility in Java module?)

如何在Java模块中指定源和目标兼容性?(How to specify source and target compatibility in Java module?)

我有一个Gradle项目,包括一个Android模块( com.android.library插件应用于build.gradle文件中)和一个Java模块( java插件应用于build.gradle文件中)。 在Java模块的build.gradle文件中,我之前指定了源和目标兼容性,如下所示:

apply plugin: 'java'

compileJava {
    sourceCompatibility = 1.7
    targetCompatibility = 1.7
}

我刚刚将项目的“Android插件for Gradle”和“Gradle Wrapper”版本更新到最新版本(分别为2.2.3和3.2.1),现在我在Java模块中看到警告如下:

Access to 'sourceCompatibility' exceeds its access rights
Access to 'targetCompatibility' exceeds its access rights

如果我将sourceCompatibilitytargetCompatibility声明移动到模块的build.gradle文件的根级别,如下所示...

apply plugin: 'java'

sourceCompatibility = 1.7
targetCompatibility = 1.7

...然后我收到警告信息,告诉我没有使用任务。

在最新的Gradle版本中指定Java模块的源和目标兼容级别的正确方法是什么?


I have a Gradle project consisting of an Android module (the com.android.library plugin is applied in the build.gradle file) and a Java module (the java plugin is applied in the build.gradle file). Within the build.gradle file of the Java module I was previously specifying the source and target compatibility as follows:

apply plugin: 'java'

compileJava {
    sourceCompatibility = 1.7
    targetCompatibility = 1.7
}

I've just updated the project's "Android Plugin for Gradle" and "Gradle Wrapper" versions to the latest releases (2.2.3 and 3.2.1 respectively) and I'm now seeing warnings in the Java module as follows:

Access to 'sourceCompatibility' exceeds its access rights
Access to 'targetCompatibility' exceeds its access rights

If I move the sourceCompatibility and targetCompatibility declarations to the root-level of the module's build.gradle file as follows...

apply plugin: 'java'

sourceCompatibility = 1.7
targetCompatibility = 1.7

... then I get warning messages telling me that the assignments are not used.

What is the correct manner of specifying the source and target compatibility level of a Java module in the latest Gradle release?


原文:https://stackoverflow.com/questions/41017544
更新时间:2024-03-19 21:03

最满意答案

在我做了搜索,并且找不到答案之后,我对此有了更多的考虑,这是我提出的解决方案(只是对其他人有用)

Psuedo第一:

  1. 显示一个页面,列出ACL $acl->getRoles()中的所有角色 (用户级别 $acl->getRoles()作为链接。
  2. 单击链接,重新加载将角色作为参数传递的页面。
    • 现在从ACL $acl->getResources()获取所有控制器 ,检查资源不是一个角色(getResources返回的数组也将包含角色)
    • 循环遍历每个控制器 ,从规则表中获取控制器 id在resource_id字段中的所有条目并爆炸额外内容 (逗号分隔操作)
    • 接下来,遍历每个动作 ,调用isAllowed (我有角色,控制器和动作)如果找到至少一个“允许”,我将控制器设置为绿色(允许访问控制器中的至少一个操作) ,否则其红色(不能访问该控制器中的任何内容)每个列表项都可单击以重新加载页面
  3. 现在,当单击控制器时,我重新加载页面,现在,当运行操作列表时,调用isAllowed我创建所选控制器的操作列表,根据isAllowed的结果将操作着色为绿色或红色

它的自我答案几乎和问题一样冗长,但它对我有用,可以清楚地了解每个角色可以做些什么。 在这里它是否会帮助任何人:

现在代码:

AdminController:

public function aclAction()
{
    $this->view->content_title = "Access Rules:";

    // Get the ACL - its stored in the session:
    $usersNs = new Zend_Session_Namespace("ZEND_SITE");
    $acl = $usersNs->acl;

    // List all Roles in the ACL:
    $roles = $acl->getRoles();
    // Pass the roles to the view:
    $this->view->roles = $roles;

    // Check if a role has been clicked on:
    $role = this->_getParam('role');
    if(!is_null($role))
    {
        // Pass the role to the view:
        $this->view->role = $role;

        // Get all the resources (controllers) from the ACL, don't add roles:
        $controllers = array();
        foreach ($acl->getResources() as $res)
        {
            if (!in_array($res, $roles))
            {
                $controllers[] = $res;
            }
        }

        // Create a Rules Model:
        $rules = new Model_ACLrules();

        // Store controllers + access:
        $all_controllers = array();

        // Check if the controller has been passed:
        $cont = $this->_getParam('cont');

        // Loop through each controller:
        foreach ($controllers as $controller)
        {
            // Get all actions for the controller:
            // THIS IS THE PART I DON'T LIKE - BUT I SEE NO WAY TO GET
            // THE RULES FROM THE ACL - THERE LOOKS TO BE A METHOD
            // BUT IT IS A PROTECTED METHOD - SO I AM GETTING THE ACTIONS 
            // FROM THE DB, BUT THIS MEANS TWO SQL QUERIES - ONE TO FIND
            // THE RESOURCE FROM THE DB TO GET ITS ID THEN ONE TO FIND
            // ALL THE EXTRAS FOR IT:
            $all_rules = $rules->findAllActions($controller);

            // Store if the role is allowed access somewhere in the controller:
            $allowed = false;

            // Store selected controller actions:
            $cont_actions = array();

            // Loop through all returned row of actions for the resource:
            foreach ($all_rules as $rule)
            {
                // Split the extras field:
                $extras = explode(",", $rule->extras); 

                // Check if the role has access to any of the actions:
                foreach ($extras as $act)
                {
                    // Store matching selected controller:
                    $match = ($cont==$controller)?true:false;

                    // Store the action if we are looking at a resource:
                    if ($match)$temp = array("action"=>$act,"allowed"=>false);

                    // Check if the role is allowed:
                    if ($acl->isAllowed($role,$controller,$act))
                    {
                        // Change the controllers allowed to ture as at least one item is allowed:
                        $allowed = true;

                        // Change the matched controllers action to true:
                        if ($match)$temp = array("action"=>$act,"allowed"=>true);
                    }

                    // Check if the action has already been added if we are looking at a resource:
                    if ($match)
                    {
                        $add = true;
                        // This is done because there could be several rows of extras, for example
                        // login is allowed for guest, then on another row login is denied for member,
                        // this means the login action will be found twice for the resource,
                        // no point in showing login action twice:
                        foreach ($cont_actions as $a)
                        {
                            // Action already in the array, don't add it again:
                            if ($a['action'] == $act) $add = false;
                        }
                        if($add) $cont_actions[] = $temp;
                    }
                }
            }

            // Pass a list of controllers to the view:
            $all_controllers[] = array("controller" => $controller, "allowed" => $allowed);

            // Check if we had a controller:
            if(!is_null($cont))
            {
                // Pass the selected controller to the view:
                $this->view->controller = $cont;

                // Check if this controller in the loop is the controller selected:
                if ($cont == $controller)
                {
                    // Add the controller + actions to the all rules:
                    $this->view->actions = $cont_actions;
                }
            }
        }

        // Pass the full controller list to the view:
        $this->view->controllers = $all_controllers;
    }   
}

接下来的视图:acl.phtml:

<h2>Roles:</h2>
<ul>
    <?php 
        foreach ($this->roles as $name)
        {
            echo '<li><a href="'.$this->baseUrl('admin/acl') . '/role/' . $name . '">' . ucfirst($name) . '</a><br/></li>';
        }
    ?>
</ul>

<?php if (isset($this->controllers)): ?>
    <h2><?php echo ucfirst($this->role); ?>'s Controllers:</h2>
    <ul>
        <?php
            $array = $this->controllers;
            sort($array);
            foreach ($array as $controller)
            {
                $font = ($controller['allowed'])?'green':'red';
                echo '<li><a href="'.$this->baseUrl('admin/acl') . '/role/' . $this->role . '/cont/'.$controller['controller'].'" style="color:'.$font.';">'.ucfirst($controller['controller']).'</a></li>';    
            }   
        ?>
    </ul>

    <?php if (isset($this->controller)): ?>
        <h2><?php echo ucfirst($this->role)."'s, ".ucfirst($this->controller);?> Actions:</h2>
        <ul>
            <?php 
                $array = $this->actions;
                sort($array);
                foreach ($array as $action)
                {
                    $font = ($action['allowed'])?'green':'red';
                    echo '<li><font style="color:'.$font.';">'.ucfirst($action['action']).'</font></li>';
                }
            ?>
        </ul>
    <?php endif;?>
<?php endif; ?>

例:

我希望这对某人有帮助,我会暂时保持开放状态,任何人都可以提出更好的解决方案 - 或者可以改进答案?


Well after I did abit of searching, and couldn't find an answer, I had a bit more of a think about this and here is the solution I came up with (just incase its useful for someone else):

Psuedo first:

  1. Show a page, listing all of the roles (user levels) from the ACL $acl->getRoles() as a link.
  2. Click a link, reload the page passing the role as a parameter.
    • Now grab all the controllers from ACL $acl->getResources() checking that the resource insn't a role (the array returned by getResources will also contain the roles).
    • loop through each controller, get all entries from the rules table where the controller id is in the resource_id field and explode the extras (comma seperated actions)
    • Next, loop through each action, calling isAllowed (I have the role, controller, and action). IF at least one "allowed" is found, I colour the controller green (allowed access to at least one action in the controller), otherwise its red (no access to anything in that controller) each list item being clickable to reload the page
  3. Now when a controller is clicked, I reload the page, now, when running through the list of actions, calling isAllowed I create a list of the actions for the selected controller, colouring the action green or red based on the result of isAllowed

The answer its self is almost as long winded as the question, but it works for me, giving a very clear picture of what each role can do. Here it is if its going to help anyone:

Now for the code:

AdminController:

public function aclAction()
{
    $this->view->content_title = "Access Rules:";

    // Get the ACL - its stored in the session:
    $usersNs = new Zend_Session_Namespace("ZEND_SITE");
    $acl = $usersNs->acl;

    // List all Roles in the ACL:
    $roles = $acl->getRoles();
    // Pass the roles to the view:
    $this->view->roles = $roles;

    // Check if a role has been clicked on:
    $role = this->_getParam('role');
    if(!is_null($role))
    {
        // Pass the role to the view:
        $this->view->role = $role;

        // Get all the resources (controllers) from the ACL, don't add roles:
        $controllers = array();
        foreach ($acl->getResources() as $res)
        {
            if (!in_array($res, $roles))
            {
                $controllers[] = $res;
            }
        }

        // Create a Rules Model:
        $rules = new Model_ACLrules();

        // Store controllers + access:
        $all_controllers = array();

        // Check if the controller has been passed:
        $cont = $this->_getParam('cont');

        // Loop through each controller:
        foreach ($controllers as $controller)
        {
            // Get all actions for the controller:
            // THIS IS THE PART I DON'T LIKE - BUT I SEE NO WAY TO GET
            // THE RULES FROM THE ACL - THERE LOOKS TO BE A METHOD
            // BUT IT IS A PROTECTED METHOD - SO I AM GETTING THE ACTIONS 
            // FROM THE DB, BUT THIS MEANS TWO SQL QUERIES - ONE TO FIND
            // THE RESOURCE FROM THE DB TO GET ITS ID THEN ONE TO FIND
            // ALL THE EXTRAS FOR IT:
            $all_rules = $rules->findAllActions($controller);

            // Store if the role is allowed access somewhere in the controller:
            $allowed = false;

            // Store selected controller actions:
            $cont_actions = array();

            // Loop through all returned row of actions for the resource:
            foreach ($all_rules as $rule)
            {
                // Split the extras field:
                $extras = explode(",", $rule->extras); 

                // Check if the role has access to any of the actions:
                foreach ($extras as $act)
                {
                    // Store matching selected controller:
                    $match = ($cont==$controller)?true:false;

                    // Store the action if we are looking at a resource:
                    if ($match)$temp = array("action"=>$act,"allowed"=>false);

                    // Check if the role is allowed:
                    if ($acl->isAllowed($role,$controller,$act))
                    {
                        // Change the controllers allowed to ture as at least one item is allowed:
                        $allowed = true;

                        // Change the matched controllers action to true:
                        if ($match)$temp = array("action"=>$act,"allowed"=>true);
                    }

                    // Check if the action has already been added if we are looking at a resource:
                    if ($match)
                    {
                        $add = true;
                        // This is done because there could be several rows of extras, for example
                        // login is allowed for guest, then on another row login is denied for member,
                        // this means the login action will be found twice for the resource,
                        // no point in showing login action twice:
                        foreach ($cont_actions as $a)
                        {
                            // Action already in the array, don't add it again:
                            if ($a['action'] == $act) $add = false;
                        }
                        if($add) $cont_actions[] = $temp;
                    }
                }
            }

            // Pass a list of controllers to the view:
            $all_controllers[] = array("controller" => $controller, "allowed" => $allowed);

            // Check if we had a controller:
            if(!is_null($cont))
            {
                // Pass the selected controller to the view:
                $this->view->controller = $cont;

                // Check if this controller in the loop is the controller selected:
                if ($cont == $controller)
                {
                    // Add the controller + actions to the all rules:
                    $this->view->actions = $cont_actions;
                }
            }
        }

        // Pass the full controller list to the view:
        $this->view->controllers = $all_controllers;
    }   
}

Next the view: acl.phtml:

<h2>Roles:</h2>
<ul>
    <?php 
        foreach ($this->roles as $name)
        {
            echo '<li><a href="'.$this->baseUrl('admin/acl') . '/role/' . $name . '">' . ucfirst($name) . '</a><br/></li>';
        }
    ?>
</ul>

<?php if (isset($this->controllers)): ?>
    <h2><?php echo ucfirst($this->role); ?>'s Controllers:</h2>
    <ul>
        <?php
            $array = $this->controllers;
            sort($array);
            foreach ($array as $controller)
            {
                $font = ($controller['allowed'])?'green':'red';
                echo '<li><a href="'.$this->baseUrl('admin/acl') . '/role/' . $this->role . '/cont/'.$controller['controller'].'" style="color:'.$font.';">'.ucfirst($controller['controller']).'</a></li>';    
            }   
        ?>
    </ul>

    <?php if (isset($this->controller)): ?>
        <h2><?php echo ucfirst($this->role)."'s, ".ucfirst($this->controller);?> Actions:</h2>
        <ul>
            <?php 
                $array = $this->actions;
                sort($array);
                foreach ($array as $action)
                {
                    $font = ($action['allowed'])?'green':'red';
                    echo '<li><font style="color:'.$font.';">'.ucfirst($action['action']).'</font></li>';
                }
            ?>
        </ul>
    <?php endif;?>
<?php endif; ?>

Example:

I hope this is helpful to someone, I will leave it open for now incase anyone can suggest a better solution - or maybe improve on the answer?

相关问答

更多
  • 您的代码中没有“管理员”角色。 只有'管理员'角色。 您只有3个角色: $this->addRole(new Zend_Acl_Role('guests')); $this->addRole(new Zend_Acl_Role('users'), 'guests'); $this->addRole(new Zend_Acl_Role('admins'), 'users'); 最后添加's' There is no 'admin' role in your code. There's only a ' ...
  • 我的实现: 问题#1 class App_Model_Acl extends Zend_Acl { const ROLE_GUEST = 'guest'; const ROLE_USER = 'user'; const ROLE_PUBLISHER = 'publisher'; const ROLE_EDITOR = 'editor'; const ROLE_ADMIN = 'admin'; ...
  • 是的 , 这是zend框架的美妙之处,你可以使用多少你想要使用的。 为了您的要求,只需在您的index.php中包含zend加载器以及一些引导它的代码即可,现在您可以使用ZEND的任何组件。 Yes, This is the beauty of zend framework you can use how much you want to use. For your requirement just include the zend loader in your index.php and some mor ...
  • Zend Framework 2.0中的ACL组件现在称为Zend\Permissions\Acl 。 我强烈建议您查看参考手册 。 在该页面上对该术语进行简单搜索即可立即实现。 The ACL component in Zend Framework 2.0 is now called Zend\Permissions\Acl. I highly recommend reviewing the reference manual. A simple search for the term on that pa ...
  • 设置acl后,必须将其保存在注册表中,以便在布局/视图中使用它: ... $acl->allow('guest','login'); Zend_Registry::set('Zend_Acl', $acl); ... else { $role = 'guest'; } Zend_Registry::set('Zend_Acl_Role', $role); 编辑: 我想我错过了使用导航的布局/视图文件: // set acl, role $this->navigation()->setAcl(Z ...
  • 第一解决方案 避免这些例外,例如 if (!$acl->has($your_resource)) { // .. handle it the way you need } 第二个 在ErrorController中处理这些异常,即: if ($errors->exception instanceof Zend_Acl_Exception) { // send needed headers... // prepare log message... // render info: ...
  • 使用inheritsRole函数。 这样: if($this->acl->inheritsRole('user', 'admin')) { /* display content for an admin */ } Use the inheritsRole function. Such that: if($this->acl->inheritsRole('user', 'admin')) { /* display content for an admin */ }
  • 在我做了搜索,并且找不到答案之后,我对此有了更多的考虑,这是我提出的解决方案(只是对其他人有用) : Psuedo第一: 显示一个页面,列出ACL $acl->getRoles()中的所有角色 (用户级别 $acl->getRoles()作为链接。 单击链接,重新加载将角色作为参数传递的页面。 现在从ACL $acl->getResources()获取所有控制器 ,检查资源不是一个角色(getResources返回的数组也将包含角色) 。 循环遍历每个控制器 ,从规则表中获取控制器 id在resource_ ...
  • 您绝不仅限于使用角色系统来表示Zend_Acl组。 例如: 在一个应用程序中,我有我的基本用户对象,实现Zend_Acl_Role_Interface ,在这种情况下返回一个特定于用户的字符串。 为简单起见,我们只需说出user-1 ,其中数字部分是用户的唯一ID。 初始化用户对象时,它会将自身添加到ACL,其中特定于用户的角色继承自更通用的角色(类似于组)。 if(!$acl->hasRole($this)) { $acl->addRole($this, $this->role); // Let' ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)